Dear all,
I'm new in arduino programming.
I want to use Arduino UNO board to turn ON/OFF and blinking a stacklight 3 colors (RED, AMBER, GREEN) accordant to 3 contact switches (for each color, S_FWD ---> RED, S_RWD ---> AMBER, S_MDO ---> GREEN).
My code is tested and works well when:
S_MDO button is pushed, GREEN light: OFF
During this moment:
a. S_FWD button is pushed, RED light: ON
b. S_RWD button is pushed, AMBER light: ON
I want to insert the code statement in case: if S_MDO button is latched, during the RED (or AMBER):ON, the RED (or AMBER), it should be blinking in that moment. And when S_MDO is pushed, blinking stops.
Could anyone please tell me how to do that ?
Thanks and very appreciates your helps.
const unsigned int RED = A5; // control RED stacklight
const unsigned int AMBER = A4; // control AMBER stacklight
const unsigned int GREEN = A3; // control GREEN stacklight
const unsigned int FWD = 10; // Forward SW (for RED light)
const unsigned int RWD = 11; // Reward SW (for AMBER light)
const unsigned int MDO = 12; // Door SW (for GREEN light)
int S_FWD, S_RWD, S_MDO; // Buttons (with INPUT_PULLUP resistors)
void setup(){
pinMode(RED, OUTPUT);
pinMode(AMBER, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(FWD, INPUT_PULLUP);
pinMode(RWD, INPUT_PULLUP);
pinMode(MDO, INPUT_PULLUP);
Sleep(); // Outputs pins (A3, A4, A5) go to HIGH: Stack Lights turn OFF
}
void loop(){
S_FWD = digitalRead(FWD); // Forward limit switch
S_RWD = digitalRead(RWD); // Reward limit switch
S_MDO = digitalRead(MDO); // Main door detected switch
if (S_MDO == HIGH){
digitalWrite(GREEN, LOW); // The door is opened, GREEN:ON, others lights turn OFF
digitalWrite(RED, HIGH);
digitalWrite(AMBER, HIGH);
}
else if (S_MDO == LOW){ // During the door is closed,
digitalWrite(GREEN, HIGH); // GREEN light turns OFF immediately and AMBER/RED light turns ON dependant on their limit SW positions.
if (S_RWD == LOW){ // Reward limit SW touched (GND)
digitalWrite(AMBER, LOW); // AMBER:ON
digitalWrite(RED, HIGH); // RED:OFF
[i] // TO DO: If Door opens during AMBER:ON ----> GREEN:ON immediately, AMBER flashing with A_Flashing() function
// When the Door is closed, AMBER:ON, GREEN:OFF [/i]
}
else if (S_FWD == LOW){ // Forward limit SW touched (GND) ---> RED:ON, AMBER:OFF
digitalWrite(RED, LOW);
digitalWrite(AMBER, HIGH);
[i]// TO DO: If Door opens during RED:ON ----> GREEN:ON immediately, RED flashing with R_Flasching() function
// When the Door is closed, RED:ON, GREEN:OFF [/i]
}
}
}
void Sleep(){ // Set ALL stack lights OFF
digitalWrite(RED, HIGH);
digitalWrite(AMBER, HIGH);
digitalWrite(GREEN, HIGH);
}
void A_Flashing(){
digitalWrite(AMBER, HIGH); // AMBER:OFF
digitalWrite(RED, HIGH);
delay (50);
digitalWrite(AMBER, LOW); // AMBER:ON
digitalWrite(RED, HIGH);
delay (50);
}
void R_Flashing(){
digitalWrite(AMBER, HIGH);
digitalWrite(RED, HIGH); // RED:OFF
delay (50);
digitalWrite(AMBER, HIGH);
digitalWrite(RED, LOW); // RED:ON
delay (50);
}