add fountain animation

This commit is contained in:
Sean 2022-04-17 20:28:42 -04:00
parent a9ff478c8e
commit 4e72a85d49
6 changed files with 194 additions and 1 deletions

View file

@ -38,6 +38,10 @@ void loop() {
shift_squares();
break;
case FOUNTAIN:
fountain();
break;
case RAINBOWCORNER:
rainbow_corner();
break;

View file

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

49
fountain.ino Normal file
View file

@ -0,0 +1,49 @@
/********************************** FOUNTIAN **********************************\
| Light shoots up the middle of the cube then once it reaches the top fall |
| back down on the outside of the cube. After it hits the bottom it changes |
| color and starts again |
| |
| Written By: Asher Glick |
| Modified By: S. Dugre to use asynchronous timer |
\******************************************************************************/
int fountain_loop;
void fountain() {
if (currentState != lastState) {
lastState = currentState;
Serial.print("New State = ");
Serial.println(currentState);
currentTimer = 0;
maxTimer = 0.2 * 1000 * 1000 / 16; // 0.1 seconds
fountain_loop = 0;
}
if ( timerReset) {
switch (fountain_loop){
case 0 ... 3:
//for (int z = 0; z <= 3; z++) {
drawBoxWalls(color,1,1,fountain_loop,2,2,fountain_loop);
flushBuffer();
clearBuffer();
fountain_loop++;
timerReset = false;
break;
case 4 ... 7:
//for (int z = 3; z >= 0; z--) {
drawBoxWalls(color,0,0,7-fountain_loop,3,3,7-fountain_loop);
flushBuffer();
clearBuffer();
if(fountain_loop >= 7){
fountain_loop = 0;
color = nextColor(color);
}
else fountain_loop++;
timerReset = false;
break;
}
}
}

83
shift_squares.ino Normal file
View file

@ -0,0 +1,83 @@
/******************************** SHIFT SQUARES *******************************\
| Three 2x2x2 squares start on the cube each a red green or blue. then they |
| randomly move around the cube one at a time, if they crash into each other |
| then then both leds turn on and while they occupy the same space they apear |
| a different color |
| |
| Written By: Asher Glick |
| Modified By: S. Dugre to use asynchronous timer |
\******************************************************************************/
//int animationSpeed = 100;
int blx = 2; // blue x
int bly = 0; // blue y
int blz = 0; // blue z
int rdx = 0; // red x
int rdy = 2; // red y
int rdz = 0; // red z
int gnx = 0; // green x
int gny = 0; // green y
int gnz = 2; // green z
int * mover = &blx;
int shift_squares_loop;
void shift_squares() {
if (currentState != lastState) {
lastState = currentState;
Serial.print("New State = ");
Serial.println(currentState);
currentTimer = 0;
maxTimer = 0.3 * 1000 * 1000 / 16; // 0.5 seconds
shift_squares_loop = 0;
}
if ( timerReset) {
switch (shift_squares_loop){
case 0:
switch (random(0,9)) {
case 0: mover = &blx; break;
case 1: mover = &bly; break;
case 2: mover = &blz; break;
case 3: mover = &rdx; break;
case 4: mover = &rdy; break;
case 5: mover = &rdz; break;
case 6: mover = &gnx; break;
case 7: mover = &gny; break;
case 8: mover = &gnz; break;
}
*mover = (((*mover)+2)%4)-1;
drawBox(blue ,abs(blx),abs(bly),abs(blz),abs(blx)+1,abs(bly)+1,abs(blz)+1);
drawBox(red ,abs(gnx),abs(gny),abs(gnz),abs(gnx)+1,abs(gny)+1,abs(gnz)+1);
drawBox(green,abs(rdx),abs(rdy),abs(rdz),abs(rdx)+1,abs(rdy)+1,abs(rdz)+1);
flushBuffer();
clearBuffer();
shift_squares_loop = 1;
timerReset = false;
break;
case 1:
*mover = (((*mover)+2)%4)-1;
drawBox(blue ,abs(blx),abs(bly),abs(blz),abs(blx)+1,abs(bly)+1,abs(blz)+1);
drawBox(red ,abs(gnx),abs(gny),abs(gnz),abs(gnx)+1,abs(gny)+1,abs(gnz)+1);
drawBox(green,abs(rdx),abs(rdy),abs(rdz),abs(rdx)+1,abs(rdy)+1,abs(rdz)+1);
flushBuffer();
clearBuffer();
shift_squares_loop = 2;
timerReset = false;
break;
case 2:
shift_squares_loop = 0;
timerReset = false;
break;
}
}
}

56
tunnel.ino Normal file
View file

@ -0,0 +1,56 @@
/*********************************** TUNNEL ***********************************\
|
| Modified By: S. Dugre to use asynchronous timer
\******************************************************************************/
int color1[] = {R,R,R,R,B,B,B,B};
int bright1[] = {2,4,6,8,2,4,6,8};
int color2[] = {B,B,B,B,R,R,R,R};
int bright2[] = {8,6,4,2,8,6,4,2};
int index[] = {0,1,2,3,4,5,6,7};
//int animationSpeed =100;
void tunnel() {
if (currentState != lastState) {
lastState = currentState;
Serial.print("New State = ");
Serial.println(currentState);
currentTimer = 0;
maxTimer = 6250; // 100ms (100,000 us / 16 us)
}
if ( timerReset) {
drawBoxWalls(color1[index[0]],bright1[index[0]],1,1,0,2,2,0);
drawBoxWalls(color2[index[0]],bright2[index[0]],1,1,0,2,2,0);
drawBoxWalls(color1[index[1]],bright1[index[1]],1,1,1,2,2,1);
drawBoxWalls(color2[index[1]],bright2[index[1]],1,1,1,2,2,1);
drawBoxWalls(color1[index[2]],bright1[index[2]],1,1,2,2,2,2);
drawBoxWalls(color2[index[2]],bright2[index[2]],1,1,2,2,2,2);
drawBoxWalls(color1[index[3]],bright1[index[3]],1,1,3,2,2,3);
drawBoxWalls(color2[index[3]],bright2[index[3]],1,1,3,2,2,3);
drawBoxWalls(color1[index[4]],bright1[index[4]],0,0,3,3,3,3);
drawBoxWalls(color2[index[4]],bright2[index[4]],0,0,3,3,3,3);
drawBoxWalls(color1[index[5]],bright1[index[5]],0,0,2,3,3,2);
drawBoxWalls(color2[index[5]],bright2[index[5]],0,0,2,3,3,2);
drawBoxWalls(color1[index[6]],bright1[index[6]],0,0,1,3,3,1);
drawBoxWalls(color2[index[6]],bright2[index[6]],0,0,1,3,3,1);
drawBoxWalls(color1[index[7]],bright1[index[7]],0,0,0,3,3,0);
drawBoxWalls(color2[index[7]],bright2[index[7]],0,0,0,3,3,0);
flushBuffer();
clearBuffer();
for (int i = 0; i < 8; i++){
//index[i] = index[i]==7?0:index[i]+1;
index[i] = (index[i]+1)%8;
}
timerReset = false;
}
}