add trifade animation

This commit is contained in:
Sean 2022-04-18 20:31:30 -04:00
parent c9479eaee8
commit 86376ae168
5 changed files with 70 additions and 4 deletions

View file

@ -1,5 +1,3 @@
// WIP. 4/13/2022: added pin change interrupt to handle changing animations
#include "config.h"
#include "cubeplex.h"
@ -44,6 +42,10 @@ void loop() {
case PLANARSPIN:
planar_spin();
break;
case TRIFADE:
trifade();
break;
case RAINBOWCORNER:

View file

@ -8,6 +8,7 @@ typedef enum STATE {
SHIFTSQUARES,
FOUNTAIN,
PLANARSPIN,
TRIFADE,
RAINBOWCORNER,
PLANARFLOP3D
};

View file

@ -582,7 +582,7 @@ int currentTimer = 0;
int maxTimer = 6250; // 100ms delay / 16uS interrupt time
int nextState(int state) {
return (state + 1) % 6;
return (state + 1) % 7;
}
// the interrupt function to display the leds (T2 = 8 bit timer)

View file

@ -18,7 +18,7 @@ void fountain() {
Serial.println(currentState);
currentTimer = 0;
maxTimer = 0.2 * 1000 * 1000 / 16; // 0.1 seconds
maxTimer = 0.2 * 1000 * 1000 / 16; // 0.2 seconds
fountain_loop = 0;
}

63
trifade.ino Normal file
View file

@ -0,0 +1,63 @@
/********************************** 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;
}
}
}