Hello all, and happy thanksgiving if you celebrate it!
I recently built a Charliecube based on Asher Glick's tutorial. The issue I'm having with it is that it doesn't cycle through the animations as it should. It just gets stuck on the "planarSpin" animation. If I comment out the animations one by one, I've found that the "shiftSquares" animation does cycle over to "tunnel", but that's the only one that works properly.
#include "cubeplex.h"
int color = red;
int count = 0;
void setup() {
initCube();
animationMax = 10; // how many secconds until the animation is told to progress
}
void loop() {
planarSpin();
fountian();
trifade();
shiftSquares();
tunnel();
chaseTheDot();
planarFlop3D();
//SeqTheDot(); //for testing one LED at a time, and finding wiring errors
}
void planarSpin() {
.
.
.
void shiftSquares() {
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;
continuePattern = true;
while(continuePattern) {
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();
delay(animationSpeed);
*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();
delay(animationSpeed*2);
}
}
void tunnel() {
continuePattern = true;
int animationSpeed =100;
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[] = {6,4,2,0,6,4,2,0};
int bright2[] = {8,6,4,2,8,6,4,2};
int index[] = {0,1,2,3,4,5,6,7};
while (continuePattern) {
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;
}
delay(animationSpeed);
}
}
.
.
.
Also, I tried to add a pushbutton to manually cycle the modes, but that isn't working either. I think I figured out the issue with this, correct me if I'm wrong. I think the issue is that as soon as the "void loop" starts, it jumps out to the "void planarSpin", so it never comes back to the loop to read the pushbutton. I believe the solution to this would be to free up one of the hardware interrupt pins, and use that for the pushbutton instead? (I already moved the output that was on pin 13 to A5, to get rid of the ghosting from the onboard led, which is why I used pin 13 as my input.)
#include "cubeplex.h"
int color = red;
int count = 0;
int currentStatus = LOW;
int previousStatus = LOW;
void setup() {
initCube();
pinMode(13, INPUT);
Serial.begin(9600);
animationMax = 30; // how many secconds until the animation is told to progress
}
void loop() {
currentStatus = digitalRead(13);
if (currentStatus == HIGH && previousStatus == LOW){
count = count + 1;
};
previousStatus = currentStatus;
if(count == 0) {planarSpin(); }
if(count == 1) {fountian(); }
if(count == 2) {trifade(); }
if(count == 3) {shiftSquares(); }
if(count == 4) {tunnel(); }
if(count == 5) {chaseTheDot(); }
if(count == 6) {planarFlop3D(); }
if(count == 7) {count =0; }
Serial.print("Count = ");
Serial.println(count);
//SeqTheDot(); //for testing one LED at a time, and finding wiring errors
}
void planarSpin() {
.
.
.
void shiftSquares() {
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;
continuePattern = true;
while(continuePattern) {
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();
delay(animationSpeed);
*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();
delay(animationSpeed*2);
}
}
void tunnel() {
continuePattern = true;
int animationSpeed =100;
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[] = {6,4,2,0,6,4,2,0};
int bright2[] = {8,6,4,2,8,6,4,2};
int index[] = {0,1,2,3,4,5,6,7};
while (continuePattern) {
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;
}
delay(animationSpeed);
}
}
.
.
.
(Some code has been ellipsed to meet the 9000 character post limit)