Components and supplies
Jumper wires (generic)
Arduino UNO
Keypad 3x4 Analog out
Keypad 4x4 Analog out
LCD 16x2 with serial
Project description
Code
full keyboard writing on an LCD
arduino
I play with my daughter to write words on a screen
1/* 2 simple code to test and use analog kepads to make a full Keyboard 3 4 2021 ~ by rogermarin 5 this code is in public domain 6 thsi program uses the serial monitor to see tue values for each button 7 because the hrdware di not 100% reliable on the readings I gave a + - 5 ohms of tolerance to all the mesurements 8*/ 9 10 11#include <LiquidCrystal_I2C.h> 12LiquidCrystal_I2C lcd(0x27,16,2); 13 14int analogPin0 = A0; // Or any pin you are using 15int analogPin1 = A1; // Or any pin you are using 16int analogPin2 = A2; // Or any pin you are using 17int val0 = 0; // an auxiliar variable to store the value 18int val1 = 0; // an auxiliar variable to store the value 19int val2 = 0; // an auxiliar variable to store the value 20char key; 21 22void setup () 23{ 24 Serial.begin (9600); //Setup serial to use the serial monitor 25 26 27// initialize the lcd 28lcd.init(); 29lcd.backlight(); 30lcd.setCursor(0,0); 31} 32 33void show (String key) //Here is where the things get print 34{ 35 if (key == "Clear") //Clear Screen 36 { 37 lcd.init(); 38 lcd.setCursor(0,0); 39 } 40 else if (key == "ENTER") //Cahnges Line 41 { 42 lcd.setCursor(0,1); 43 } 44 else 45 { 46 lcd.print(key); 47 }; 48delay(500); 49} 50void loop () // Here we read the Keyboard 51{ 52 val0 = analogRead (analogPin0); //3x4 keypad 53 if (val0 >= 1020 and val0 <= 1024){show("9");}; 54 if (val0 >= 925 and val0<= 935){show("0");}; 55 if (val0 >= 845 and val0<= 855){show("Clear");}; 56 if (val0 >= 785 and val0<= 795){show("O");}; 57 if (val0 >= 725 and val0 <= 735){show ("P");}; 58 if (val0 >= 675 and val0 <=685 ){show("!");}; 59 if (val0 >= 640 and val0 <= 645){show("K");}; 60 if (val0 >= 600 and val0 <= 610){show("L");}; 61 if (val0 >= 565 and val0<= 575){show("YES");}; 62 if (val0 >= 530 and val0 <= 550){show("M");}; 63 if (val0 >= 500 and val0<=515){show(" ");}; 64 if (val0 >= 485 and val0<=495){show("#");}; 65 66 val1 = analogRead (analogPin1); //4x4 keypad 1 67 if (val1 >= 1020 and val1 <= 1024){show ("5");}; 68 if (val1 >= 925 and val1 <= 935){show("6");}; 69 if (val1 >= 845 and val1 <= 855){show("7");}; 70 if (val1 >= 785 and val1 <= 795){show("8");}; 71 if (val1 >= 675 and val1 <= 685){show("T");}; 72 if (val1 >= 630 and val1 <= 640){show("Y");}; 73 if (val1 >= 595 and val1 <= 605){show("U");}; 74 if (val1 >= 560 and val1 <= 570){show("I");}; 75 if (val1 >= 500 and val1 <= 510){show("F");}; 76 if (val1 >= 480 and val1 <= 490){show("G");}; 77 if (val1 >= 450 and val1 <= 460){show("H");}; 78 if (val1 >= 435 and val1 <= 445){show("J");}; 79 if (val1 >= 400 and val1 <= 410){show("C");}; 80 if (val1 >= 320 and val1 <= 330){show("V");}; 81 if (val1 >= 265 and val1 <= 275){show("B");}; 82 if (val1 >= 233 and val1 <= 243){show("N");}; 83 84 val2 = analogRead (analogPin2); //4x4 kepay 2 85 if (val2 >= 1020 and val2 <= 1024){show("1");}; 86 if (val2 >= 925 and val2 <= 935){show("2");}; 87 if (val2 >= 845 and val2 <= 855){show("3");}; 88 if (val2 >= 785 and val2 <= 795){show("4");}; 89 if (val2 >= 675 and val2 <= 685){show("Q");}; 90 if (val2 >= 630 and val2 <= 640){show("W");}; 91 if (val2 >= 595 and val2 <= 605){show("E");}; 92 if (val2 >= 560 and val2 <= 570){show("R");}; 93 if (val2 >= 500 and val2 <= 510){show("ARDUINO");}; 94 if (val2 >= 480 and val2 <= 490){show("A");}; 95 if (val2 >= 450 and val2 <= 460){show("S");}; 96 if (val2 >= 435 and val2 <= 445){show("D");}; 97 if (val2 >= 400 and val2 <= 410){show("ENTER");}; 98 if (val2 >= 320 and val2 <= 330){show("DELETE");}; 99 if (val2 >= 265 and val2 <= 275){show("Z");}; 100 if (val2 >= 233 and val2 <= 243){show("X");}; 101 102}
Comments
Only logged in users can leave comments
roger_marin
0 Followers
•0 Projects
0