diff --git a/cubeplex.h b/cubeplex.h index e88b8d5..b930110 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) % 8; + return (state + 1) % 9; } // the interrupt function to display the leds (T2 = 8 bit timer) diff --git a/rainbow_corner.ino b/rainbow_corner.ino index 0343228..71caf55 100644 --- a/rainbow_corner.ino +++ b/rainbow_corner.ino @@ -1,11 +1,13 @@ /******************************* RAINBOW CORNER *******************************\ | Found on the internet.... | | | -| Modified By: S. Dugre to use asynchronous timer - - NOT WORKING GOOD. IT SCREWS UP ANIMATION PROGRESSION +| Modified By: S. Dugre to use asynchronous timer | +| | \******************************************************************************/ +int loop_rc1, loop_rc2, loop_rc3, loop_rc4; +int moveAxisState; + byte spectrum2[24][3] = { {8,0,0},{7,1,0},{6,2,0},{5,3,0},{4,4,0},{3,5,0},{2,6,0},{1,7,0}, {0,8,0},{0,7,1},{0,6,2},{0,5,3},{0,4,4},{0,3,5},{0,2,6},{0,1,7}, @@ -15,7 +17,7 @@ byte offset = 0; byte shift[3] = {0,0,0}; bool mirror[3] = {false,false,false}; byte anim[8] = {0,2,0,1,0,2,0,1}; - + void drawCube() { for (byte x = 0; x <= 3; x++) { for (byte y = 0; y <= 3; y++) { @@ -36,20 +38,25 @@ void drawCube() { flushBuffer(); clearBuffer(); offset = offset == 0 ? 23 : offset - 1; - //delay(75); - currentTimer = 0; + //delay(75); + //timerReset = false; } void moveAxis(byte axis) { for (int n = 1;n <= 3; n++) { shift[axis] = n; drawCube(); + delay(75); } + mirror[axis] = not mirror[axis]; drawCube(); + delay(75); + for (int n = 2;n >= 0; n--) { shift[axis] = n; drawCube(); + delay(75); } } @@ -63,13 +70,29 @@ void rainbow_corner() { currentTimer = 0; maxTimer = 4687; // 75 ms + + loop_rc1 = loop_rc2 = 0; + loop_rc3 = 1; + loop_rc4 = 2; + moveAxisState = 0; } if ( timerReset) { - for (byte n = 0;n <= 7;n++) { - for (byte m = 0;m < 50;m++) drawCube(); - moveAxis(anim[n]); + + if(loop_rc2 < 50){ + loop_rc2++; + drawCube(); + timerReset = false; } - timerReset = false; + else { + loop_rc2 = 0; + moveAxis(anim[loop_rc1]); + if(loop_rc1 <= 7){ + loop_rc1++; + } + else{ + loop_rc1 = 0; + } + } } }