63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
/********************************** TRI-FADE **********************************\
|
|
| This animation fades through the red green and blue colors of the leds |
|
|
| creating different mixtures of each of the colors. |
|
|
| |
|
|
| Written By: Asher Glick |
|
|
| Modified By: S. Dugre to use asynchronous timer |
|
|
\******************************************************************************/
|
|
|
|
//int animationSpeed = 100;
|
|
int loop_tf;
|
|
|
|
void trifade() {
|
|
|
|
if (currentState != lastState) {
|
|
|
|
lastState = currentState;
|
|
Serial.print("New State = ");
|
|
Serial.println(currentState);
|
|
|
|
currentTimer = 0;
|
|
maxTimer = 0.2 * 1000 * 1000 / 16; // 0.2 seconds
|
|
loop_tf = 1;
|
|
}
|
|
|
|
if ( timerReset) {
|
|
|
|
switch(loop_tf){
|
|
|
|
case 0 ... 7:
|
|
drawBox(blue,8-loop_tf,0,0,0,3,3,3);
|
|
drawBox(red,loop_tf+1,0,0,0,3,3,3);
|
|
flushBuffer();
|
|
clearBuffer();
|
|
loop_tf++;
|
|
timerReset = false;
|
|
break;
|
|
|
|
case 8 ... 15:
|
|
// red fade out, green fade in
|
|
drawBox(red,8-(loop_tf % 8),0,0,0,3,3,3);
|
|
drawBox(green,(loop_tf % 8)+1,0,0,0,3,3,3);
|
|
flushBuffer();
|
|
clearBuffer();
|
|
loop_tf++;
|
|
timerReset = false;
|
|
break;
|
|
|
|
case 16 ... 23:
|
|
// green fade out, blue fade in
|
|
drawBox(green,8-(loop_tf % 8),0,0,0,3,3,3);
|
|
drawBox(blue,(loop_tf % 8)+1,0,0,0,3,3,3);
|
|
flushBuffer();
|
|
clearBuffer();
|
|
loop_tf++;
|
|
timerReset = false;
|
|
break;
|
|
|
|
default:
|
|
loop_tf = 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|