March Madness - Slide controls

This is the start of a bigger project that is going to use the fader slides to control a DMX stage lighting display. The number and row of X's on the display reflect the position of the 3 sliders on the danger shield.


//************************************************************************
//*	Fader
//*	
//*		(C) 2010 by Mark Sproul
//*		Open source as per standard Arduino code
//************************************************************************

#include 
#include 
#include 
#include 
#include 

#include "WProgram.h"
#include "HardwareSerial.h"

//these are our analog input pins
#define SLIDER1_PIN 2
#define SLIDER2_PIN 1
#define SLIDER3_PIN 0


short	gFader1;
short	gFader2;
short	gFader3;

short	gPrevFader1;
short	gPrevFader2;
short	gPrevFader3;

//************************************************************************
void	GetFaderText(int faderValue, char *faderText, int maxLen)
{
int	ii;

	sprintf(faderText, "%4d ", faderValue);
	for (ii=0; ii<(faderValue / 70); ii++)
	{
		strcat(faderText, "X");
	}
	
	//*	put spaces after it so it fills up the line
	while (strlen(faderText) < maxLen)
	{
		strcat(faderText, " ");
	}
}

//************************************************************************
void UpdateFaderInfo()
{
char	textString[48];


	Serial.write(0x1B);
	Serial.write('H');
	GetFaderText(gFader1, textString, 19);
	Serial.println(textString);

	GetFaderText(gFader2, textString, 19);
	Serial.println(textString);

	GetFaderText(gFader3, textString, 19);
	Serial.println(textString);

}


//************************************************************************
void setup()
{
int	ii;

	Serial.begin(9600);
	Serial.println();
	Serial.println("Fader");


	gFader1	=	0;
	gFader2	=	0;
	gFader3	=	0;

}

//************************************************************************
void loop()
{

	gFader1	=	analogRead(SLIDER1_PIN);
	gFader2	=	analogRead(SLIDER2_PIN);
	gFader3	=	analogRead(SLIDER3_PIN);


	if ((gFader1 != gPrevFader1) || (gFader2 != gPrevFader2) || (gFader3 != gPrevFader3))
	{
		UpdateFaderInfo();		
		gPrevFader1	=	gFader1;
		gPrevFader2	=	gFader2;
		gPrevFader3	=	gFader3;
	
		delay(200);
	}
}