From 86376ae1680069b45264ad7ef161d569005e749b Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 18 Apr 2022 20:31:30 -0400 Subject: [PATCH] add trifade animation --- charlieCube.ino | 6 +++-- config.h | 1 + cubeplex.h | 2 +- fountain.ino | 2 +- trifade.ino | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 trifade.ino diff --git a/charlieCube.ino b/charlieCube.ino index 47c6e30..7d9ce3c 100644 --- a/charlieCube.ino +++ b/charlieCube.ino @@ -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: diff --git a/config.h b/config.h index e8c7813..e1da3c9 100644 --- a/config.h +++ b/config.h @@ -8,6 +8,7 @@ typedef enum STATE { SHIFTSQUARES, FOUNTAIN, PLANARSPIN, + TRIFADE, RAINBOWCORNER, PLANARFLOP3D }; diff --git a/cubeplex.h b/cubeplex.h index 3b3445e..d14d83b 100644 --- a/cubeplex.h +++ b/cubeplex.h @@ -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) diff --git a/fountain.ino b/fountain.ino index 539b9db..d1acaee 100644 --- a/fountain.ino +++ b/fountain.ino @@ -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; } diff --git a/trifade.ino b/trifade.ino new file mode 100644 index 0000000..de14cc5 --- /dev/null +++ b/trifade.ino @@ -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; + } + } +}