I try to make a program which two LED blink continuously by press A, B and C on membrane keypad 4X4. If user press A the LED will keep blinking for 1 second each, B for 5 second and C for 10 second. Since I am new with Arduino, I try it using IF statement which LED blink with given time but not continuously blink.
type or paste code here
#include <Key.h>
#include <Keypad.h>
#define LED1 10
#define LED2 11
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(19200);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
char customkey = customKeypad.getKey();
if(customkey){
if(customkey == 'A'){
conditionA();
}
else if(customkey == 'B'){
conditionB();
}
else if(customkey == 'C'){
conditionC();
}
}
}
void conditionA(){
digitalWrite(LED1, HIGH);
delay(1000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(1000);
digitalWrite(LED2, LOW);
}
void conditionB(){
digitalWrite(LED1, HIGH);
delay(5000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(5000);
digitalWrite(LED2, LOW);
}
void conditionC(){
digitalWrite(LED1, HIGH);
delay(10000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(10000);
digitalWrite(LED2, LOW);
}
I try to change if statement to while statement but it keep looping indefinitely. I didn't find any similar program that I can refer in the forum. Can anyone suggest the best solution to create this program. Thanks in advance.