Hi
Can anyone help me add a line of code to a project that is ongoing?
I have a relay switch sequence a, ab, a, abc, all off on a relay pcb connected to the Arduino and I need to add a line of code so that when the sequence is started and the relays have finished then I need a 2 second break where if you press the start button to re-initiate another sequence then it’s locked out and wont operate.
The existing code is here::
#define out_a 9
#define out_b 8
#define out_c 7
#define out_d 6
#define in1 4
unsigned long delay_ms = millis();
unsigned long seq_delay=50; //delay in ms
unsigned long start_delay=25; //delay ms
unsigned long mode_delay=millis();
byte mode=0;
bool start=false;
void setup() {
Serial.begin(9600);
pinMode(in1,INPUT_PULLUP);
pinMode(out_a,OUTPUT);
pinMode(out_b,OUTPUT);
pinMode(out_c,OUTPUT);
pinMode(out_d,OUTPUT);
digitalWrite(out_a,HIGH);
digitalWrite(out_b,HIGH);
digitalWrite(out_c,HIGH);
digitalWrite(out_d,HIGH);
}
void loop() {
switch (mode){
//ON = LOW
//OFF = HIGH
case 1:
//a on
digitalWrite(out_a,LOW);
break;
case 2:
//a anb b on
digitalWrite(out_a,LOW);
digitalWrite(out_b,LOW);
break;
case 3:
//a on (b off)
digitalWrite(out_a,LOW);
digitalWrite(out_b,HIGH);
break;
case 4:
//a on, b on,
digitalWrite(out_a,LOW);
digitalWrite(out_b,LOW);
break;
case 5:
//a on, b on, c on
digitalWrite(out_a,LOW);
digitalWrite(out_b,LOW);
digitalWrite(out_c,LOW);
break;
case 6:
//then all off
digitalWrite(out_a,HIGH);
digitalWrite(out_b,HIGH);
digitalWrite(out_c,HIGH);
digitalWrite(out_d,HIGH);
mode=0;
start=false;
break;
}
if (start){
if ((millis()-mode_delay)>=seq_delay){
mode_delay=millis();
/*Serial.print("mode ");
Serial.print(mode);
Serial.print(“; a=”);
Serial.print(!digitalRead(out_a));
Serial.print(“; b=”);
Serial.print(!digitalRead(out_b));
Serial.print(“; c=”);
Serial.println(!digitalRead(out_c));
*/
mode++;
}
}
if (!digitalRead(in1)){
if ((millis()-delay_ms)>=start_delay){
start=true;
}
} else {
delay_ms = millis();
}
}