Fio Controller

//Fiber Optic Chandelier Controller Board
//Written by Bill Heaster
//http://ApexLogic.net

//////////
//Define some constant variables
//////////

//slider pot pins
const int redIn= A3;
const int greenIn = A4;
const int blueIn = A5;

//variables to store the outgoing data
int redOut = 0;
int blueOut = 0;
int greenOut = 0;

int tempR , tempG, tempB = 0;

//standby state
bool standby = false;
bool first = true;

//counter stuff


void setup()
{
	//set the pin modes
	pinMode(redIn, INPUT);
	pinMode(greenIn, INPUT);
	pinMode(blueIn, INPUT);
	
	//begin serial link to Xbee
	Serial.begin(9600);
	
}

void pushData()
{
	tempR = redOut;
	tempB = blueOut;
	tempG = greenOut;	
}

bool newData()
{
	if(tempR == redOut)
	{
		if(tempG == greenOut)
		{
			if (tempB == blueOut)
			{
				return false;
			}
		}
	}
	else
	return true;
}

void loop()
{	
	
	
	while(Serial.available()>0)
	{
		int inByte = Serial.read();
		
		//if we recieved standby char
		if (inByte == 'A')
		{
			standby = true;
		}
	}
	
	
	//every loop cycle we read the status of the slider pots
	redOut = analogRead(redIn)/4;
	delay(10);
	blueOut = analogRead(blueIn)/4 ;
	delay(10);
	greenOut = analogRead(greenIn)/4;
	delay(10);		
	
	
	if(first)
	{
	pushData();
	first = false;	
	}
	
	
	// if we have new slider values we need to come out of standby
	if(newData()== true)
	{
		standby = false;		
	}	
	
	if(standby == false)
	{
		//send the data to the chandelier
		//packet structure -> [#r,g,b]
		Serial.print('#');
		Serial.print(redOut, BYTE);
		Serial.print(blueOut, BYTE);
		Serial.print(greenOut, BYTE);
	}
	
	//wait for a half second so we are not just draining the battery by transmitting. 
	//lowering this will make the controls more responsive
	//however will keep the xbee transmitting, thus killing the battery. 
	delay(500);
	
	//save the data so we have something to compare too next loop
	pushData();
	
}

Leave a Reply