added planar spin animation

This commit is contained in:
Sean 2022-04-17 23:09:53 -04:00
parent 4e72a85d49
commit c9479eaee8
4 changed files with 78 additions and 2 deletions

View file

@ -42,9 +42,13 @@ void loop() {
fountain();
break;
case PLANARSPIN:
planar_spin();
break;
case RAINBOWCORNER:
rainbow_corner();
break;
break;
case PLANARFLOP3D:
planarFlop3D();

View file

@ -7,6 +7,7 @@ typedef enum STATE {
TUNNEL,
SHIFTSQUARES,
FOUNTAIN,
PLANARSPIN,
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) % 5;
return (state + 1) % 6;
}
// the interrupt function to display the leds (T2 = 8 bit timer)

71
planar_spin.ino Normal file
View file

@ -0,0 +1,71 @@
/********************************* PLANAR SPIN ********************************\
| A plane of light spins around the virtical center of the cube and changes |
| colors after a certian number of rotations |
| |
| Written By: Asher Glick |
| Modified By: S. Dugre to use asynchronous timer |
\******************************************************************************/
//int animationSpeed = 50;
int spinsPerColor = 5; // a spin is actually half a revolution
int spin;
int loop_ps;
void planar_spin() {
if (currentState != lastState) {
lastState = currentState;
Serial.print("New State = ");
Serial.println(currentState);
currentTimer = 0;
maxTimer = 0.1 * 1000 * 1000 / 16; // 100 ms
loop_ps = 0;
spin = 0;
}
if ( timerReset) {
//int x = 0;
//int y = 0;
//for (int i = 0; i < spinsPerColor; i++) {
if(spin < spinsPerColor){
//for (int x = 0; x < 3; x++) {
switch(loop_ps){
case 0 ... 2:
drawLine(color,loop_ps,0,0,3-loop_ps,3,0);
drawLine(color,loop_ps,0,1,3-loop_ps,3,1);
drawLine(color,loop_ps,0,2,3-loop_ps,3,2);
drawLine(color,loop_ps,0,3,3-loop_ps,3,3);
flushBuffer();
clearBuffer();
loop_ps++;
timerReset = false;
break;
//for (int y = 0; y < 3; y++) {
case 3 ... 5:
drawLine(color,3,(loop_ps % 3),0,0,3-(loop_ps % 3),0);
drawLine(color,3,(loop_ps % 3),1,0,3-(loop_ps % 3),1);
drawLine(color,3,(loop_ps % 3),2,0,3-(loop_ps % 3),2);
drawLine(color,3,(loop_ps % 3),3,0,3-(loop_ps % 3),3);
flushBuffer();
clearBuffer();
loop_ps++;
timerReset = false;
break;
default:
loop_ps = 0;
spin++;
break;
}
}
else {
color = nextColor(color);
spin = 0;
}
}
}