Components and supplies
Arduino UNO
keypad 4×4
Alphanumeric LCD, 16 x 2
Project description
Code
untitled
arduino
1#include <LiquidCrystal.h> 2 3#include <Keypad.h> 4 5const int ROW_NUM = 4; //four rows 6const int COLUMN_NUM = 4; //four columns 7 8char keys[ROW_NUM][COLUMN_NUM] = { 9 {'1','2','3', 'A'}, 10 {'4','5','6', 'B'}, 11 {'7','8','9', 'C'}, 12 {'*','0','#', 'D'} 13}; 14 15byte pin_rows[ROW_NUM] = {3,6,7,8}; //connect to the row pinouts of the keypad 16byte pin_column[COLUMN_NUM] = {9,10,1,13}; //connect to the column pinouts of the keypad 17 18Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 19 20String inputString; 21long inputInt; 22LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 23void setup() { 24 Serial.begin(9600); 25 inputString.reserve(10); 26 myservo.attach(10);// maximum number of digit for a number is 10, change if needed 27} 28 29void loop() { 30 char key = keypad.getKey(); 31 32 if (key) { 33 Serial.println(key); 34 35 if (key >= '0' && key <= '9') { // only act on numeric keys 36 inputString += key; // append new character to input string 37 } else if (key == '#') { 38 if (inputString.length() > 0) { 39 inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER 40 inputString = ""; // clear input 41 // DO YOUR WORK HERE 42 43 } 44 } else if (key == '*') { 45 inputString = ""; // clear input- 46 } 47 } 48 if (key==3456){ 49 myservo.write(90); 50 51 } 52 else{ 53 myservo.write(0); 54 } 55 } 56
untitled
arduino
1#include <LiquidCrystal.h> 2 3#include <Keypad.h> 4 5const int 6 ROW_NUM = 4; //four rows 7const int COLUMN_NUM = 4; //four columns 8 9char 10 keys[ROW_NUM][COLUMN_NUM] = { 11 {'1','2','3', 'A'}, 12 {'4','5','6', 'B'}, 13 14 {'7','8','9', 'C'}, 15 {'*','0','#', 'D'} 16}; 17 18byte pin_rows[ROW_NUM] 19 = {3,6,7,8}; //connect to the row pinouts of the keypad 20byte pin_column[COLUMN_NUM] 21 = {9,10,1,13}; //connect to the column pinouts of the keypad 22 23Keypad keypad 24 = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 25 26String 27 inputString; 28long inputInt; 29LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 30void 31 setup() { 32 Serial.begin(9600); 33 inputString.reserve(10); 34 myservo.attach(10);// 35 maximum number of digit for a number is 10, change if needed 36} 37 38void loop() 39 { 40 char key = keypad.getKey(); 41 42 if (key) { 43 Serial.println(key); 44 45 46 if (key >= '0' && key <= '9') { // only act on numeric keys 47 inputString 48 += key; // append new character to input string 49 } else if (key 50 == '#') { 51 if (inputString.length() > 0) { 52 inputInt = inputString.toInt(); 53 // YOU GOT AN INTEGER NUMBER 54 inputString = ""; // clear 55 input 56 // DO YOUR WORK HERE 57 58 } 59 } else if (key == '*') 60 { 61 inputString = ""; // clear input- 62 } 63 } 64 65 if (key==3456){ 66 myservo.write(90); 67 68 } 69 else{ 70 myservo.write(0); 71 72 } 73 } 74
untitled
arduino
1#include <LiquidCrystal.h> 2 3#include <Keypad.h> 4 5const int ROW_NUM = 4; //four rows 6const int COLUMN_NUM = 4; //four columns 7 8char keys[ROW_NUM][COLUMN_NUM] = { 9 {'1','2','3', 'A'}, 10 {'4','5','6', 'B'}, 11 {'7','8','9', 'C'}, 12 {'*','0','#', 'D'} 13}; 14 15byte pin_rows[ROW_NUM] = {3,6,7,8}; //connect to the row pinouts of the keypad 16byte pin_column[COLUMN_NUM] = {9,10,1,13}; //connect to the column pinouts of the keypad 17 18Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); 19 20String inputString; 21long inputInt; 22LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 23void setup() { 24 Serial.begin(9600); 25 inputString.reserve(10); 26 myservo.attach(10);// maximum number of digit for a number is 10, change if needed 27} 28 29void loop() { 30 char key = keypad.getKey(); 31 32 if (key) { 33 Serial.println(key); 34 35 if (key >= '0' && key <= '9') { // only act on numeric keys 36 inputString += key; // append new character to input string 37 } else if (key == '#') { 38 if (inputString.length() > 0) { 39 inputInt = inputString.toInt(); // YOU GOT AN INTEGER NUMBER 40 inputString = ""; // clear input 41 // DO YOUR WORK HERE 42 43 } 44 } else if (key == '*') { 45 inputString = ""; // clear input- 46 } 47 } 48 if (key==3456){ 49 myservo.write(90); 50 51 } 52 else{ 53 myservo.write(0); 54 } 55 } 56
Downloadable files
website_10_CrjCbuUDpC.png
website_10_CrjCbuUDpC.png
Comments
Only logged in users can leave comments
pranavmadhavaram
1 Followers
•19 Projects
0