71 lines
2.1 KiB
C++
71 lines
2.1 KiB
C++
/********************************* 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;
|
|
}
|
|
|
|
}
|
|
}
|