Hello all,
I have worked through as many examples as I could find but I am not getting something right.
I understand this program is basic and not the best way to sequence something but here is what I have so far. Just starting out please have a look. Right now the button is pressed and it runs the sequence on time and waits for button press to start again.
I would like to press the button the first time, loop sequence until button is pressed a second time then stop sequence and wait for button press to repeat above.
// cycle test
const int buttonPin = 12;
const int USB1 = 1; //assigns digital output 1 the name USB1
const int fan1 = 2; //assigns digital output 2 the name fan1
const int LED1 = 3; //assigns digital output 3 the name LED1
const int USB2 = 4; //assigns digital output 4 the name USB2
const int fan2 = 5; //assigns digital output 5 the name fan2
const int LED2 = 6; //assigns digital output 6 the name LED2
const int USB3 = 7; //assigns digital output 7 the name USB3
const int fan3 = 8; //assigns digital output 8 the name fan3
const int LED3 = 9; //assigns digital output 9 the name LED3
; int x = 0
; int buttonState = 0; // variables will change:
int oldButtonState = LOW;
void setup()
{
oldButtonState = digitalRead(buttonPin);
pinMode(buttonPin, OUTPUT);
pinMode(USB1, OUTPUT); //initalizes all 9 outputs
pinMode(fan1, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(USB2, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(USB3, OUTPUT);
pinMode(fan3, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
//check if button pressed, if so enter program condition (inside if statement)
int newButtonState = digitalRead(buttonPin);
if (newButtonState == HIGH && oldButtonState == LOW) {
if (x == 0) {
// Start sequencing all loads in order on boards 1 thru 3
delay(1000);
// Turn on USB1
digitalWrite(USB1, LOW); // close USB1 contacts
delay(600); // delay xxxx sec
digitalWrite(USB1, HIGH); // open USB1 contacts
delay(600); // delay xxxx sec
// Turn on fan1
digitalWrite(fan1, LOW); // close fan1 contacts
delay(600); // delay xxxx sec
digitalWrite(fan1, HIGH); // open fan1 contacts
delay(600); // delay xxxx sec
// Turn on LED1
digitalWrite(LED1, LOW); // close LED1 contacts
delay(600); // delay xxxx sec
digitalWrite(LED1, HIGH); // open LED1 contacts
delay(600); // delay xxxx sec
delay(1000); // Board #2
// Turn on USB2
digitalWrite(USB2, LOW); // close USB2 contacts
delay(600); // delay xxxx sec
digitalWrite(USB2, HIGH); // open USB2 contacts
delay(600); // delay xxxx sec
// Turn on fan2
digitalWrite(fan2, LOW); // close fan2 contacts
delay(600); // delay xxxx sec
digitalWrite(fan2, HIGH); // open fan2 contacts
delay(600); // delay xxxx sec
// Turn on LED2
digitalWrite(LED2, LOW); // close LED2 contacts
delay(600); // delay xxxx sec
digitalWrite(LED2, HIGH); // open LED2 contacts
delay(600); // delay xxxx sec
delay(1000); // Board #3
// Turn on USB3
digitalWrite(USB3, LOW); // close USB3 contacts
delay(600); // delay xxxx sec
digitalWrite(USB3, HIGH); // open USB3 contacts
delay(600); // delay xxxx sec
// Turn on fan3
digitalWrite(fan3, LOW); // close fan3 contacts
delay(600); // delay xxxx sec
digitalWrite(fan3, HIGH); // open fan3 contacts
delay(600); // delay xxxx sec
// Turn on LED3
digitalWrite(LED3, LOW); // close LED3 contacts
delay(600); // delay xxxx sec
digitalWrite(LED3, HIGH); // open LED3 contacts
delay(600); // delay xxxx sec`
delay(100);
int X = 1;
} else {
x = 0;
}
}
oldButtonState = newButtonState;
}