Pigeon-Kicker
Published © LGPL

MEGA BREAD - 4X4 KeyPad

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

IntermediateWork in progress1 hour9,410
MEGA BREAD - 4X4 KeyPad

Things used in this project

Story

Read more

Schematics

MEGA BREAD - keypad

YouTube video Link <-- Watch me.

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

MEGA BREAD - keypad 2

-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.

Code

MEGA_BREAD_KEYPAD.ino

C/C++
This short scripting links the LCD input to the keypad output, displays it, then resets after 2 seconds.
It will also output whatever input it gets to the serial monitor.
#include <LiquidCrystal.h> //Import the LCD library
#include <Keypad.h> //Import the 4 by 4 Button pad library
int delayTimeA = 500;
int delayTimeB = 2000;
int delayTimeC = 250;
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'},
};
//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);
//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*/
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){
  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();
}
}

Credits

Pigeon-Kicker

Pigeon-Kicker

19 projects • 31 followers
Computer guru from the 80's, currently disabled veteran. Building this stuffs for my son to learn robotics.
Thanks to Mini Pigeon.

Comments