84 lines
2 KiB
C++
84 lines
2 KiB
C++
/******************************** CHASE THE DOT *******************************\
|
|
| A single point of light moves around the cube randomly and changes colors |
|
|
| when it tries to go out of bounds |
|
|
| |
|
|
| Inspired By: Jonah Glick |
|
|
| Written By: Asher Glick |
|
|
| |
|
|
| Modified By: S. Dugre to use asynchronous timer |
|
|
\******************************************************************************/
|
|
|
|
int xpos = 0;
|
|
int ypos = 0;
|
|
int zpos = 0;
|
|
|
|
int animationSpeed = 100;
|
|
|
|
void chaseTheDot() {
|
|
|
|
if (currentState != lastState) {
|
|
|
|
lastState = currentState;
|
|
Serial.print("New State = ");
|
|
Serial.println(currentState);
|
|
xpos = 0;
|
|
ypos = 0;
|
|
zpos = 0;
|
|
|
|
currentTimer = 0;
|
|
maxTimer = 6250; // 100 ms
|
|
}
|
|
|
|
|
|
//while (continuePattern) {
|
|
if ( timerReset) {
|
|
switch (random(0, 6)) {
|
|
case 0:
|
|
if (xpos > 0) {
|
|
xpos--;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
case 1:
|
|
if (xpos < 3) {
|
|
xpos++;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
xpos--; break;
|
|
|
|
case 2:
|
|
if (ypos > 0) {
|
|
ypos--;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
case 3:
|
|
if (ypos < 3) {
|
|
ypos++;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
ypos--; break;
|
|
|
|
case 4:
|
|
if (zpos > 0) {
|
|
zpos--;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
case 5:
|
|
if (zpos < 3) {
|
|
zpos++;
|
|
break;
|
|
}
|
|
else color = nextColor(color);
|
|
zpos--; break;
|
|
}
|
|
drawLed(color, xpos, ypos, zpos);
|
|
flushBuffer();
|
|
clearBuffer();
|
|
|
|
timerReset = false;
|
|
}
|
|
}
|