Skip to content

Instantly share code, notes, and snippets.

@fedescarpa
Created November 2, 2017 00:23
Show Gist options
  • Save fedescarpa/0f7ab46d8ef3ff639f157375c0204a75 to your computer and use it in GitHub Desktop.
Save fedescarpa/0f7ab46d8ef3ff639f157375c0204a75 to your computer and use it in GitHub Desktop.
Sketch para mapear teclado numerico a letras
#include <Keypad.h>
#include <LiquidCrystal.h>
const int ROWS = 4;
const int COLS = 3;
const char keys[ROWS][COLS] = {
{'*', '0', '#'},
{'7', '8', '9'},
{'4', '5', '6'},
{'1', '2', '3'},
};
byte colPins[COLS] = {32, 31, 30};
byte rowPins[ROWS] = {33, 34, 35, 36};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
char key = keypad.getKey();
lcd_print_if(key, '1', "Uno");
lcd_print_if(key, '2', "Dos");
lcd_print_if(key, '3', "Tres");
lcd_print_if(key, '4', "Cuatro");
lcd_print_if(key, '5', "Cinco");
lcd_print_if(key, '6', "Seis");
lcd_print_if(key, '7', "Siete");
lcd_print_if(key, '8', "Ocho");
lcd_print_if(key, '9', "Nueve");
lcd_print_if(key, '0', "Cero");
lcd_print_if(key, '*', "Asterisco");
lcd_print_if(key, '#', "Numeral");
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}
void lcd_print_if(char key, char expected, char* message) {
if (key == expected) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment