Code for Led Keypad
// LED On using Keypad
#include <Keypad.h>
#define ROW_NUM 4 // four rows
#define COLUMN_NUM 4 // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte pin_rows[ROW_NUM] = {13, 12, 11, 10}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {9, 8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
char key = keypad.getKey();
if (key) {
Serial.println(key);
if(key == '2'){
digitalWrite(13, HIGH);
}
else{
digitalWrite(13, LOW);
}
}
else{
Serial.println("Wrong Key pressed.");
}
}
Comments
Post a Comment