char c;
byte d;
byte x;
byte action;
byte arrayCall[8]; //input array
byte arrayWhite[8];
byte arrayRed[8];
byte arrayGreen[8];
byte arrayBlue[8];
byte arrayMix[8];
const int red = 3;
const int green = 5;
const int blue = 6;
const int white = 9;
void setup()
{
Serial.begin (9600);
pinMode (white, OUTPUT);
pinMode (red, OUTPUT);
pinMode (green, OUTPUT);
pinMode (blue, OUTPUT);
digitalWrite (white, LOW); //high deactivates
LEDs on the lamp unit
digitalWrite (red, HIGH);
digitalWrite (green, HIGH);
digitalWrite (blue, HIGH);
arrayWhite [0] = 119; //w //Button White
arrayWhite [1] = 104; //h
arrayWhite [2] = 105; //i
arrayWhite [3] = 116; //t
arrayWhite [4] = 101; //e
arrayRed [0] = 114;//r //Button Red
arrayRed [1] = 101;//e
arrayRed [2] = 100;//d
arrayGreen [0] = 103; //g //Button Green
arrayGreen [1] = 114; //r
arrayGreen [2] = 101; //e
arrayGreen [3] = 101; //e
arrayGreen [4] = 110; //n
arrayBlue [0] = 98;//b //Button Blue
arrayBlue [1] = 108;//l
arrayBlue [2] = 117;//u
arrayBlue [3] = 101;//e
arrayMix [0] = 109;//m //Button Mix, toggles
fast, med, slow, and very slow
arrayMix [1] = 105;//i
arrayMix [2] = 120;//x
}//end of setup
void loop()
{
while (Serial.available()) {
delay(70);
byte d = Serial.read(); // get ASCII Byte
char c = d; //convert to char
Serial.print(c);
if (d > 13) {//skips new line and carrage
return etc.
arrayCall[x] = d; //loads call memory
x++;
}
}// end of serial available
for ( x = 0; x < 8; x++) {
if (arrayCall[x] == arrayWhite
[x] && arrayCall[x] > 13
) { //action 5, white call
action = 5;
}
if (arrayCall[x] == arrayRed[x]
&& arrayCall[x] > 13 )
{ //action 4, red call
action = 4;
}
if (arrayCall[x] == arrayGreen
[x] && arrayCall[x] > 13 ) { //action 3, green call
action = 3;
}
if (arrayCall[x] == arrayBlue
[x] && arrayCall[x] > 13
) { //action 2, blue call
action = 2;
}
if (arrayCall[x] == arrayMix
[x] && arrayCall[x] > 13
) { //action 1, mix call
action = 1;
}
} // end of for
switch (action) {
case 5: //white on
digitalWrite (white, LOW );
digitalWrite (red, HIGH);
digitalWrite (green, HIGH);
digitalWrite (blue, HIGH);
clearArray();
break;
case 4: //red
digitalWrite (white, HIGH);
digitalWrite (red, LOW);
digitalWrite (green, HIGH);
digitalWrite (blue, HIGH);
clearArray();
break;
case 3: //green
digitalWrite (white, HIGH);
digitalWrite (red, HIGH);
digitalWrite (green, LOW);
digitalWrite (blue, HIGH);
clearArray();
break;
case 2: //blue
digitalWrite (white, HIGH);
digitalWrite (red, HIGH);
digitalWrite (green, HIGH);
digitalWrite (blue, LOW);
clearArray();
break;
case 1: //mix
digitalWrite (white, HIGH);
digitalWrite (red, HIGH);
digitalWrite (green, HIGH);
digitalWrite (blue, HIGH);
for (x = 255; x > 0; x--) {
analogWrite(red, x);
delay (10);
}
for (x = 0; x < 255; x++) {
analogWrite(red, x);
delay (10);
} //red up/down
for (x = 255; x > 0; x--) {
analogWrite(green, x);
delay (10);
}
for (x = 0; x < 255; x++) {
analogWrite(green, x);
delay (10);
} //green up/down
for (x = 255; x > 0; x--) {
analogWrite(blue, x);
delay (20);
}
for (x = 0; x < 255; x++) {
analogWrite(blue, x);
delay (20);
} //blue up/down
break;
} //end of action
x = 0;
}
/////subRoutines
void clearArray() {//subroutine
for ( x = 0; x < 8; x++) { //clear arrayCall
arrayCall[x] = 0;
action = 0;
}
}