#include #include #include // GDY120705 #include LiquidCrystal_I2C lcd(0x27, 16, 2);// initialisation LCD #define I2CADDR 0x20 const byte ROWS = 4; //four rows const byte COLS = 4; //three columns char keys[ROWS][COLS] = { {'1','4','7','*'}, {'2','5','8','0'}, {'3','6','9','#'}, {'A','B','C','D'} }; byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad Keypad_I2C keypad = Keypad_I2C( makeKeymap(keys), rowPins, colPins, ROWS, COLS, I2CADDR ); byte ledPin = 40; boolean blink = false; void setup(){ lcd.backlight();// active retro-eclairage Serial.begin(19200); keypad.begin( ); // GDY120705 pinMode(ledPin, OUTPUT); // sets the digital pin as output digitalWrite(ledPin, HIGH); // sets the LED on keypad.addEventListener(keypadEvent); //add an event listener for this keypad lcd.setCursor(0,1); lcd.print("Didiersee"); } void loop(){ char key = keypad.getKey(); if (key) { Serial.println(key); } if (blink){ digitalWrite(ledPin,!digitalRead(ledPin)); delay(100); } } //take care of some special events void keypadEvent(KeypadEvent key){ switch (keypad.getState()){ case PRESSED: switch (key){ case '#': digitalWrite(ledPin,!digitalRead(ledPin)); break; case '*': digitalWrite(ledPin,!digitalRead(ledPin)); break; } break; case RELEASED: switch (key){ case '*': digitalWrite(ledPin,!digitalRead(ledPin)); blink = false; break; } break; case HOLD: switch (key){ case '*': blink = true; break; } break; } }