Very big noob here , stupid question how do i set a button to have a different variable if on or off?
on value of 60000 millis one minute or off 120000 millis two minutes
code works as well as i need for now just need the timer to work for the end of loop
Thank you for the assistance ...
int relay1=2;
int relay2=3;
int relay3=4;
int relay4=5;
int relay5=6;
int relay6=7;
int relay7=8;
int relay8=9;
int input1=13;
int reset=12;
int timerstate=10;
int relay =-1;
int buzzer =11;
#include <ezButton.h>
//button for 1 or two minutes
// define button for timer 1 or two minutes
#define timer1min 60000
#define timer2min 120000
//button for start
#define LOOP_STATE_STOPPED 0
#define LOOP_STATE_STARTED 1
ezButton button(13); // create ezButton object that attach to pin 13;
int loopState = LOOP_STATE_STOPPED;
void setup() {
// put your setup code here, to run once:
pinMode (timerstate,INPUT);
pinMode (relay1,OUTPUT);
pinMode (relay2,OUTPUT);
pinMode (relay3,OUTPUT);
pinMode (relay4,OUTPUT);
pinMode (relay5,OUTPUT);
pinMode (relay6,OUTPUT);
pinMode (relay7,OUTPUT);
pinMode (relay8,OUTPUT);
pinMode (input1,INPUT);
pinMode (reset,OUTPUT);
pinMode (buzzer,OUTPUT);
button.setDebounceTime(50); // set debounce time to 50 milliseconds
digitalWrite (relay1,HIGH);
digitalWrite (relay2,HIGH);
digitalWrite (relay3,HIGH);
digitalWrite (relay4,HIGH);
digitalWrite (relay5,HIGH);
digitalWrite (relay6,HIGH);
digitalWrite (relay7,HIGH);
digitalWrite (relay8,HIGH);
// beep setup game
digitalWrite(buzzer,HIGH);
delay (300);
digitalWrite (buzzer,LOW);
delay (3000);
// waiting for start game on input1
digitalWrite(buzzer,HIGH);
delay (300);
digitalWrite (buzzer,LOW);
delay (100);
digitalWrite(buzzer,HIGH);
delay (300);
digitalWrite (buzzer,LOW);
delay (100);
digitalWrite(buzzer,HIGH);
delay (300);
digitalWrite (buzzer,LOW);
}
void loop (){
// start loop on button 13
button.loop(); // MUST call the loop() function first
if (button.isPressed()) {
if (loopState == LOOP_STATE_STOPPED)
loopState = LOOP_STATE_STARTED;
else // if(loopState == LOOP_STATE_STARTED)
loopState = LOOP_STATE_STOPPED;
}
if (loopState == LOOP_STATE_STARTED) {
// Randomly decide which relay to turn on
delay(random(1000, 5000));// random timer for loop
relay =-1;
relay = rand() % 8+1;
if (relay==1) {
digitalWrite(relay1, LOW);
delay (200);
digitalWrite(relay1,HIGH);
}
else if (relay==2) {
digitalWrite(relay2, LOW);
delay (200);
digitalWrite(relay2,HIGH);
}
else if (relay==3) {
digitalWrite(relay3,LOW);
delay (200);
digitalWrite(relay3,HIGH);
}
else if (relay==4) {
digitalWrite(relay4,LOW);
delay (200);
digitalWrite(relay4,HIGH);
}
else if (relay==5) {
digitalWrite(relay5, LOW);
delay (200);
digitalWrite(relay5,HIGH);
}
else if (relay==6) {
digitalWrite(relay6, LOW);
delay (200);
digitalWrite(relay6,HIGH);
}
else if (relay==7) {
digitalWrite(relay7, LOW);
delay (200);
digitalWrite(relay7,HIGH);
}
else if (relay==8) {
digitalWrite(relay8, LOW);
delay (200);
digitalWrite(relay8,HIGH);
}
// finish timer stop game need timer state to be 60000 or 120000 according to input timer pin 12 high or low)
//if timerstate on timerstate = timer1min or 60000 if timerstate off timerstate = timer2min or 120000
if (millis() >= (timerstate)) {
digitalWrite(buzzer,HIGH);
delay (500);
digitalWrite (buzzer,LOW);
delay (100);
digitalWrite(buzzer,HIGH);
delay (500);
digitalWrite (buzzer,LOW);
delay (100);
digitalWrite(buzzer,HIGH);
delay (900);
digitalWrite (buzzer,LOW);
delay (100);
exit(0);
}
}}