arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

doorlock.ino (1161B)


      1 #include <Key.h>
      2 #include <Keypad.h>
      3 
      4 /* the tutorial code for 3x4 Matrix Keypad with Arduino is as
      5 This code prints the key pressed on the keypad to the serial port*/
      6 
      7 #include "Keypad.h"
      8 
      9 const byte Rows= 4; //number of rows on the keypad i.e. 4
     10 const byte Cols= 3; //number of columns on the keypad i,e, 3
     11 
     12 //we will definne the key map as on the key pad:
     13 
     14 char keymap[Rows][Cols]=
     15 {
     16 {'1', '2', '3'},
     17 {'4', '5', '6'},
     18 {'7', '8', '9'},
     19 {'*', '0', '#'}
     20 };
     21 
     22 //  a char array is defined as it can be seen on the above
     23 
     24 
     25 //keypad connections to the arduino terminals is given as:
     26 
     27 byte rPins[Rows]= {A6,A5,A4,A3}; //Rows 0 to 3
     28 byte cPins[Cols]= {A2,A1,A0}; //Columns 0 to 2
     29 
     30 // command for library forkeypad
     31 //initializes an instance of the Keypad class
     32 Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);
     33 
     34 void setup()
     35 {
     36      Serial.begin(9600);  // initializing serail monitor
     37 }
     38 
     39 //If key is pressed, this key is stored in 'keypressed' variable
     40 //If key is not equal to 'NO_KEY', then this key is printed out
     41 void loop()
     42 {
     43      char keypressed = kpd.getKey();
     44      if (keypressed != NO_KEY)
     45      { 
     46           Serial.println(keypressed);
     47      }
     48 }