#include <Keypad.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int led_G = 18; //Led droit
const int led_D = 19; //Led gauche
const byte ROWS = 6; //four rows
const byte COLS = 6; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','4','5','6'},
{'7','8','9','0','A','B'},
{'C','D','E','F','G','H'},
{'I','J','K','L','M','N'},
{'O','P','Q','R','S','T'},
{'U','V','W','X','Y','Z'},
};
byte rowPins[ROWS] = {37, 36, 35, 34, 33, 32}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {45, 44, 43, 42, 41, 40}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
boolean blink = false;
boolean ledPin_state;
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Sets the digital pin as output.
pinMode(led_G, OUTPUT); // Sets the digital pin as output.
pinMode(led_D, OUTPUT); // Sets the digital pin as output.
digitalWrite(ledPin, HIGH); // Turn the LED on.
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
keypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}
void loop(){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
char key = keypad.getKey();
if (key) {
Serial.println(key);
led_flash();
}
if (blink){
digitalWrite(ledPin,!digitalRead(ledPin)); // Change the ledPin from Hi2Lo or Lo2Hi.
delay(100);
}
}
void led_flash(){
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_G, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_G, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
digitalWrite(led_D, HIGH); // turn the LED on (HIGH is the voltage level)
delay(75); // wait for a second
digitalWrite(led_D, LOW); // turn the LED off by making the voltage LOW
delay(75); // wait for a second
}
// Taking care of some special events.
void keypadEvent(KeypadEvent key){
switch (keypad.getState()){
case PRESSED:
if (key == '#') {
digitalWrite(ledPin,!digitalRead(ledPin));
ledPin_state = digitalRead(ledPin); // Remember LED state, lit or unlit.
}
break;
case RELEASED:
if (key == '*') {
digitalWrite(ledPin,ledPin_state); // Restore LED state from before it started blinking.
blink = false;
}
break;
case HOLD:
if (key == '*') {
blink = true; // Blink the LED when holding the * key.
}
break;
}
}