diff --git a/charlieCube.ino b/charlieCube.ino index 3605bb6..47c6e30 100644 --- a/charlieCube.ino +++ b/charlieCube.ino @@ -42,9 +42,13 @@ void loop() { fountain(); break; + case PLANARSPIN: + planar_spin(); + break; + case RAINBOWCORNER: rainbow_corner(); - break; + break; case PLANARFLOP3D: planarFlop3D(); diff --git a/config.h b/config.h index 2eaa51d..e8c7813 100644 --- a/config.h +++ b/config.h @@ -7,6 +7,7 @@ typedef enum STATE { TUNNEL, SHIFTSQUARES, FOUNTAIN, + PLANARSPIN, RAINBOWCORNER, PLANARFLOP3D }; diff --git a/cubeplex.h b/cubeplex.h index 3ddcb31..3b3445e 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) % 5; + return (state + 1) % 6; } // the interrupt function to display the leds (T2 = 8 bit timer) diff --git a/planar_spin.ino b/planar_spin.ino new file mode 100644 index 0000000..186362a --- /dev/null +++ b/planar_spin.ino @@ -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; + } + + } +}