Hello, ladies and gentlemen. My hope is to create a script that selects a sequence of instructions per button press and after a set amount of time executes that program. this allows me time to scroll through the sequences. the aim of each sequence is to set a different pattern on a flasher via pulses.
If it's possible I'd like 4 or more selectable sequences to allow me to do other types of flasher.
Further to this, I will be adding another relay that selects between ground and VIN but that will come when I have the basic program working as intended.
The states in the code are LEDs to show which sequence I have selected
Here is what I have so far:
int relayPin = 5;
int buttonPin = 11;
int oldButtonState = HIGH;
int x = 0;
int state1 = A0;
int state2 = A1;
int state3 = A2;
int state4 = A3;
void setup() {
// put your setup code here, to run once:
pinMode(relayPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Get the current state of the button
int newButtonState = digitalRead(buttonPin);
// Has the button gone high since we last read it?
if (newButtonState == HIGH && oldButtonState == LOW) {
if (x == 0) {
// Sequence 1
digitalWrite(state1, HIGH);
delay(100);
digitalWrite(relayPin, HIGH);
delay(5000);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(state1, LOW);
delay(100);
x = 1;
} else {
// Sequence 2
digitalWrite(state2, HIGH);
delay(100);
digitalWrite(relayPin, HIGH);
delay(5000);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(relayPin, HIGH);
delay(200);
digitalWrite(relayPin, LOW);
delay(200);
digitalWrite(state2, LOW);
delay(100);
x = 0;
}
}
// Store the button's state so we can tell if it's changed next time round
oldButtonState = newButtonState;
}
I'm very new to coding so I'm rather lost at this point, Thanks in advance for any help you can give :).