المتابعون

Keybad with i2c



رسم بياني







The Code

#include <Keypad.h> //The keypad and LCD i2c libraries
#include <Wire.h>//by hussain alarabe
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 //defining the LCD pins
#define BACKLIGHT_PIN 3


#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad3.300
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup()
           {
            Serial.begin(9600);
            lcd.begin (16,2);
            lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
            lcd.setBacklight(HIGH);
            lcd.home ();
            lcd.print("Pressy");
            delay(2000);
           }

void loop()
{
         char keypressed = myKeypad.getKey();
         if (keypressed != NO_KEY)
             {
              lcd.clear();
              lcd.print(keypressed);
         Serial.println(keypressed); //Uncomment this to show it on the serial monitor too
              }
}

thank you


ليست هناك تعليقات