MEGA BREAD series #4, the 4 by 4 input keypad. Please Note:  To Properly do this one, First build the MEGA BREAD - LCD 16X2 project.

MEGA BREAD series #4, the 4 by 4 input keypad.

Please Note:  To Properly do this one, First build the MEGA BREAD - LCD 16X2 project.

Added 4-17-2016

 

It will wait for input, find the input, output the input, then reset after 2 seconds. This is the test run for the programming selector for our Robotics Project. More to come from this entire line.

 

YouTube video Link <-- Watch me.

 

You are NOT required to build the LCD portion, The Code will also output to a serial monitor.

 

#include <LiquidCrystal.h> //Import the LCD library
#include <Keypad.h> //Import the 4 by 4 Button pad library
//Load required libraries
int delayTimeA = 500; int delayTimeB = 2000; int delayTimeC = 25;
//Set Program delays

const byte numRows= 4; //number of rows on the keypad const byte numCols= 4; //number of columns on the keypad //keymap defines the key pressed according to the row and columns just as appears on the keypad char keymap[numRows][numCols]= { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}, };
//Setup the 4 by 4 keypad
//Code that shows the the keypad connections to the arduino terminals byte rowPins[numRows] = {38,39,40,41}; //Rows 0 to 3 byte colPins[numCols]= {A12,A13,A14,A15}; //Columns 0 to 3 //initializes an instance of the Keypad class Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); //Create the variable myKeypad and import key settings

//Setup 8-Bit mode with no PWM pinouts LiquidCrystal lcd(28, 29, 30, 31, 32, 33, 34, 35, 36, 37); /*Initialize the LCD and tell it which pins are to be used for communicating*/
//Create the variable lcd and Setup the 16 by 2 LCD into 8-bit mode for loading speed
void setup() { Serial.begin(9600); // set up the LCD's number of columns and rows: lcd.begin(16, 2); }
//If key is pressed, this key is stored in 'keypressed' variable //If key is not equal to 'NO_KEY', then this key is printed out //if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process void loop() { char keypressed = myKeypad.getKey(); lcd.setCursor(0,0); lcd.print("MEGA BREAD IS..."); lcd.setCursor(0,1); lcd.print("Waiting on Input"); if (keypressed != NO_KEY){ //This is where it hangs out waiting for a key press
delay(delayTimeC); 25 ms key read pause lcd.clear(); Serial.print(keypressed); lcd.print("MEGA BREAD Read "); delay(delayTimeA); //Wait lcd.setCursor(0, 1); lcd.print ("The Input as"); delay(delayTimeA); //Wait lcd.setCursor(13, 1); lcd.print (keypressed); delay(delayTimeB); //Wait lcd.clear(); } }