Hello fellow arduino fans.
The project that I am currently stuck on is a sign with a border. The code that I have written is working great so far. My question is, How can I have a random case statement run for x amount of time before the next random case statement is called? So far I have 2 different patterns written, and I would like to have the first random one run for 10 seconds, then choose another random case, and have it run each case for 10 seconds. here is my code so far.
int pattern = 0;
int b1 = 10; //sets pin names
int b2 = 11;
int b3 = 12;
int b4 = 13;
int t1 = 2;
int t2 = 3;
int t3 = 4;
int t4 = 5;
int pinArray[] = {10, 11, 12, 13, 2, 3, 4, 5};
int pinArraytop[] = {2, 3, 4, 5};
int pinArraybottom[] = {10, 11, 12, 13};
int count = 0;
int timer = 30;
void setup () {
pinMode(b1, OUTPUT); // sets pins as outputs.
pinMode(b2, OUTPUT);
pinMode(b3, OUTPUT);
pinMode(b4, OUTPUT);
pinMode(t1, OUTPUT);
pinMode(t2, OUTPUT);
pinMode(t3, OUTPUT);
pinMode(t4, OUTPUT);
for (count=0;count<8;count++) {
pinMode(pinArray[count], OUTPUT);
}
}
void loop() {
int pattern = random(2);
switch (pattern){
case 0://CHASE
for (count=0;count<4;count++) {
digitalWrite(pinArraytop[count], HIGH);
digitalWrite(pinArraybottom[count], HIGH);
delay(timer);
digitalWrite(pinArraybottom[count + 1], HIGH);
digitalWrite(pinArraytop[count + 1], HIGH);
delay(timer);
digitalWrite(pinArraytop[count], LOW);
digitalWrite(pinArraybottom[count], LOW);
}
break;
case 1: //fill then empty
digitalWrite(b1, HIGH);
digitalWrite(t1, HIGH);
delay(100);
digitalWrite(b2, HIGH);
digitalWrite(t2, HIGH);
delay(100);
digitalWrite(b3, HIGH);
digitalWrite(t3, HIGH);
delay(100);
digitalWrite(b4, HIGH);
digitalWrite(t4, HIGH);
delay(100);
digitalWrite(b1, LOW);
digitalWrite(t1, LOW);
delay(100);
digitalWrite(b2, LOW);
digitalWrite(t2, LOW);
delay(100);
digitalWrite(b3, LOW);
digitalWrite(t3, LOW);
delay(100);
digitalWrite(b4, LOW);
digitalWrite(t4, LOW);
delay(100);
break;
}
}