Got it all sorted, probably not the most efficient way but it works and I have even created a little countdown piezo and two buttons for different sequence times.
byte pins[] = {9,10,11,12, };
int pinCount = sizeof(pins) / sizeof(pins[0]);
int piezoPin = 8;
const byte pinButton = (2,4);
void(* resetFunc) (void) = 0;
void setup () {
for (int i = 0; i < pinCount; i++) {
pinMode(pins[i], OUTPUT) ; // setup all of the neccesary LED pins
}
pinMode(pinButton, INPUT) ; // setup the button pin
Serial.begin(9600) ; // setup the serial for debugging
randomSeed(analogRead(A0)); // so you don't get the same sequence every time you run
}
void LightSequence() {
int randomNum = random(pinCount) ; // pick random light to turn on.
int pin = pins[randomNum];
pins[randomNum] = pins[pinCount-1];
pinCount--;
Serial.println(randomNum); // print the chosen light in the serial
digitalWrite(pin, HIGH) ; // turn on the randomly chosen light
int randomTime = random(500, 3000) ; // pick a random amount of time to wait, the lowest being the minimum and the highest being the maxium
Serial.println(randomTime); // print the chosen time in the serial
delay(randomTime) ; //wait the random time
digitalWrite(pin, LOW) ; // turn off the light
}
void LightSequence2() {
int randomNum = random(pinCount) ; // pick random light to turn on.
int pin = pins[randomNum];
pins[randomNum] = pins[pinCount-1];
pinCount--;
Serial.println(randomNum); // print the chosen light in the serial
digitalWrite(pin, HIGH) ; // turn on the randomly chosen light
int randomTime = random(50, 7500) ; // pick a random amount of time to wait, the lowest being the minimum and the highest being the maxium
Serial.println(randomTime); // print the chosen time in the serial
delay(randomTime) ; //wait the random time
digitalWrite(pin, LOW) ; // turn off the light
}
void LightDisplay() {
LightSequence() ; // trigger a random light, and wait for it to turn off
LightSequence() ; // trigger a random light, and wait for it to turn off
LightSequence() ; // trigger a random light, and wait for it to turn off
LightSequence() ; // trigger a random light, and wait for it to turn off
Serial.println("End"); //print end in the serial to show when the sequence has ended
}
void LightDisplay2() {
LightSequence2() ; // trigger a random light, and wait for it to turn off
LightSequence2() ; // trigger a random light, and wait for it to turn off
LightSequence2() ; // trigger a random light, and wait for it to turn off
LightSequence2() ; // trigger a random light, and wait for it to turn off
Serial.println("End"); //print end in the serial to show when the sequence has ended
}
void loop () {
int button = digitalRead(2) ; //setup the button's value to be used
if (button == HIGH) { //when the button is pressed
delay (2000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 1000, 2000);
delay(3000);
LightDisplay() ; //trigger the light sequence
resetFunc();
}
int button4 = digitalRead(4) ; //setup the button's value to be used
if (button4 == HIGH) { //when the button is pressed
delay (2000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 100, 500);
delay(1000);
tone(piezoPin, 1000, 2000);
delay(3000);
LightDisplay2() ; //trigger the light sequence
resetFunc();
}
}