I am trying to use an Arduino to open random locks at a random time, I have some code but it re uses the same pin output more than once and I don't want it to do this. It needs to use all of the outputs and only once. Thanks in advance.
void setup () {
for (int i = 0; i > 13; i++) {
pinMode(i, OUTPUT) ; // setup all of the neccesary LED pins
}
pinMode(2, INPUT) ; // setup the button pin
Serial.begin(9600) ; // setup the serial for debugging
}
void LightSequence() {
int randomNum = random(10, 14) ; // pick random light to turn on.
// the lowest variable is the lowest light that turns on, and the highest is
// the one above the higheest light, so that can be adjusted for more or
// less lights
Serial.println(randomNum); // print the chosen light in the serial
digitalWrite(randomNum, 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(randomNum, 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 loop () {
int button = digitalRead(2) ; //setup the button's value to be used
if (button == 1) { //when the button is pressed
LightDisplay() ; //trigger the light sequence
}
}