From 4e72a85d4955dd126849477d6e9ba1feeaf41313 Mon Sep 17 00:00:00 2001 From: Sean Date: Sun, 17 Apr 2022 20:28:42 -0400 Subject: [PATCH] add fountain animation --- charlieCube.ino | 4 +++ config.h | 1 + cubeplex.h | 2 +- fountain.ino | 49 ++++++++++++++++++++++++++++ shift_squares.ino | 83 +++++++++++++++++++++++++++++++++++++++++++++++ tunnel.ino | 56 ++++++++++++++++++++++++++++++++ 6 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 fountain.ino create mode 100644 shift_squares.ino create mode 100644 tunnel.ino diff --git a/charlieCube.ino b/charlieCube.ino index 9a20cb7..3605bb6 100644 --- a/charlieCube.ino +++ b/charlieCube.ino @@ -38,6 +38,10 @@ void loop() { shift_squares(); break; + case FOUNTAIN: + fountain(); + break; + case RAINBOWCORNER: rainbow_corner(); break; diff --git a/config.h b/config.h index 17a6c3a..2eaa51d 100644 --- a/config.h +++ b/config.h @@ -6,6 +6,7 @@ typedef enum STATE { RAINBOWRANDOM, TUNNEL, SHIFTSQUARES, + FOUNTAIN, RAINBOWCORNER, PLANARFLOP3D }; diff --git a/cubeplex.h b/cubeplex.h index e54200f..3ddcb31 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) % 4; + return (state + 1) % 5; } // the interrupt function to display the leds (T2 = 8 bit timer) diff --git a/fountain.ino b/fountain.ino new file mode 100644 index 0000000..539b9db --- /dev/null +++ b/fountain.ino @@ -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; + } + } +} diff --git a/shift_squares.ino b/shift_squares.ino new file mode 100644 index 0000000..756ba17 --- /dev/null +++ b/shift_squares.ino @@ -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; + } + } +} diff --git a/tunnel.ino b/tunnel.ino new file mode 100644 index 0000000..98a5435 --- /dev/null +++ b/tunnel.ino @@ -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; + + } +}