Thanks again!
Yeah I figure I could either make an array with my values so that I can reference them elsewhere but I found it easier to create a function with 4 variables that I just manually input values for in the code. The point of the previous code is to light up 4 columns of LEDs simultaneously, which 4 columns I am lighting up changes, so I have put the appropriate delay in there. My code is working perfectly at the moment (watching my little cube flash away :D)
If you are curious, this is what I ended up implementing:
int led[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37};
int ground[] = {50,51,52,53};
char Ptimer = 0.1; //timer set low enough for persistence of vision to be observed
int timer = 1000; //generic timer delay
int count = 0;
int count1 = 0;
void setup() {
for (int i = 0; i < 16; i++){
pinMode(led[i], OUTPUT);
}
for (int x = 0; x < 4; x++){
pinMode(ground[x], OUTPUT);
}
digitalWrite(ground[0], LOW);
digitalWrite(ground[1], HIGH);
digitalWrite(ground[2], HIGH);
digitalWrite(ground[3], HIGH);
}
void ascend(){
digitalWrite(ground[0], LOW);
delay(Ptimer);
digitalWrite(ground[0], HIGH);
delay(Ptimer);
digitalWrite(ground[1], LOW);
delay(Ptimer);
digitalWrite(ground[1], HIGH);
delay(Ptimer);
digitalWrite(ground[2], LOW);
delay(Ptimer);
digitalWrite(ground[2], HIGH);
delay(Ptimer);
digitalWrite(ground[3], LOW);
delay(Ptimer);
digitalWrite(ground[3], HIGH);
}
void reset() {
for (int i = 0; i < 16; i++){
digitalWrite(led[i], LOW);
}
for (int x = 0; x < 4; x++){
digitalWrite(ground[x], HIGH);
}
}
void spiral(int a, int b, int c, int d) {
while (count < timer){
digitalWrite(led[a], HIGH);
digitalWrite(led[b], HIGH);
digitalWrite(led[c], HIGH);
digitalWrite(led[d], HIGH);
ascend();
count++;
}
count = 0;
reset();
}
void loop() {
//-------------------------------------------------------------
// Flashes cube layers upwards getting progressively slower
//-------------------------------------------------------------
for(int x = 0; x < 16; x++){
digitalWrite(led[x], HIGH);
}
while(count < 50){
digitalWrite(ground[3], HIGH);
digitalWrite(ground[0], LOW);
delay(count);
digitalWrite(ground[0], HIGH);
digitalWrite(ground[1], LOW);
delay(count);
digitalWrite(ground[1], HIGH);
digitalWrite(ground[2], LOW);
delay(count);
digitalWrite(ground[2], HIGH);
digitalWrite(ground[3], LOW);
delay(count);
count++;
}
count = 0;
reset();
delay(200);
//---------------------------------------------------
// Spiral code - anti-clockwise vertical spiral
//---------------------------------------------------
while (count1 < 10){
spiral(0,5,10,15);
spiral(1,5,10,14);
spiral(2,6,9,13);
spiral(3,6,9,12);
spiral(7,6,9,8);
spiral(11,10,5,4);
spiral(15,10,5,0);
spiral(14,10,5,1);
spiral(13,9,6,2);
spiral(12,9,6,3);
spiral(8,9,6,7);
spiral(4,5,10,15);
count1++;
}
count1 = 0;
count = 0;
reset();
delay(200);
//--------------------------------------------------------
// Sideways sweep
//-------------------------------------------------------
while (count1 < 10){
spiral(0,1,2,3);
spiral(4,5,6,7);
spiral(8,9,10,11);
spiral(12,13,14,15);
spiral(3,7,11,15);
spiral(2,6,10,14);
spiral(1,5,9,13);
spiral(0,4,8,12);
spiral(12,13,14,15);
spiral(8,9,10,11);
spiral(4,5,6,7);
spiral(0,1,2,3);
spiral(0,4,8,12);
spiral(1,5,9,13);
spiral(2,6,10,14);
spiral(3,7,11,15);
count1++;
}
count1 = 0;
delay(200);
}