/* @file CustomKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact [email protected]
||
|| @description
|| | Demonstrates changing the keypad size and key values.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <Wire.h>
const byte ROWS = 4; /* four rows */
const byte COLS = 4; /* four columns */
/* define the symbols on the buttons of the keypads */
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {10, 11, 12, 13}; /* connect to the row pinouts of the keypad */
byte colPins[COLS] = {A0, A1, A2, A3}; /* connect to the column pinouts of the keypad */
/* initialize an instance of class NewKeypad */
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
lcd.init(); // initialize the lcd
lcd.backlight();
Serial.begin(9600); /* Define baud rate for serial communication */
}
void loop() {
{
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
int adc_val;
adc_val = analogRead(A1); /* Read input from keypad */
if (adc_val>850)
{
Serial.print("Key Pressed : ");
Serial.println("0");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("0");
delay(100);
}
else if ( adc_val>450 && adc_val<510)
{
Serial.print("Key Pressed : ");
Serial.println("1");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("1");
delay(100);
}
else if ( adc_val>300 && adc_val<350)
{
Serial.print("Key Pressed : ");
Serial.println("2");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("2");
delay(100);
}
else if ( adc_val>230 && adc_val<270)
{
Serial.print("Key Pressed : ");
Serial.println("3");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("3");
delay(100);
}
else if ( adc_val>160 && adc_val<180)
{
Serial.print("Key Pressed : ");
Serial.println("4");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("4");
delay(100);
}
else if ( adc_val>145 && adc_val<155)
{
Serial.print("Key Pressed : ");
Serial.println("5");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("5");
delay(100);
}
else if ( adc_val>125 && adc_val<135)
{
Serial.print("Key Pressed : ");
Serial.println("6");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("6");
delay(100);
}
else if ( adc_val>105 && adc_val<120)
{
Serial.print("Key Pressed : ");
Serial.println("7");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("7");
delay(100);
}
else if ( adc_val>92 && adc_val<99)
{
Serial.print("Key Pressed : ");
Serial.println("8");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("8");
delay(100);
}
else if ( adc_val>82 && adc_val<90)
{
Serial.print("Key Pressed : ");
Serial.println("9");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("9");
delay(100);
}
else if ( adc_val>77 && adc_val<81)
{
Serial.print("Key Pressed : ");
Serial.println("A");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("A");
delay(100);
}
else if ( adc_val>72 && adc_val<76)
{
Serial.print("Key Pressed : ");
Serial.println("B");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("B");
delay(100);
}
else if ( adc_val>63 && adc_val<68)
{
Serial.print("Key Pressed : ");
Serial.println("C");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("C");
delay(100);
}
else if ( adc_val>60 && adc_val<62)
{
Serial.print("Key Pressed : ");
Serial.println("D");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("D");
delay(100);
}
else if ( adc_val>57 && adc_val<59)
{
Serial.print("Key Pressed : ");
Serial.println("E");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("#");
delay(100);
}
else if( adc_val>52 && adc_val<56)
{
Serial.print("Key Pressed : ");
Serial.println("F");
lcd.setCursor(0,0);
lcd.print("Key Pressed : ");
lcd.setCursor(0,1);
lcd.print("*");
delay(100);
}
else
{
}
delay(100);
}