LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)
Home > 4×4 Keypad with 7-Segment LED

4×4 Keypad with 7-Segment LED

Keypads and displays provide a human interface to your applications. This project consists of a seven-segment display and 4×4 matrix keypad connected to a Propeller FLiP Module. When a keypad button is pressed the value or character will be shown on the seven-segment display and a piezo speaker will play a confirmation tone. This program provides a template which can be expanded for other purposes, including setting motor speed with the touch keypad, and positioning a servo to ten different locations.

To make this project work on an Activity Board, you will need to leave off the piezospeaker and be careful not to let resistor leads touch. Breadboard space will be limited.

 

Build It

This 4×4 matrix keypad circuitry is based on two other examples: Read a 4×4 Matrix Keypad (from Propeller C – Simple Devices), and the BlocklyProp Propeller Reference for 4×4 matrix keypad (Sensor > 4 x 4 Keypad). The seven-segment display circuitry is similar to the Propeller C – Simple Circuits Seven-Segment Display tutorial; however, wiring the 4×4 keypad and a seven-segment display together requires some changes to the schematic so the two systems can be viewed right-side up on your breadboard.

Parts List

  • (1) – USB A to Micro B Cable (#805-00016)
  • (1) – Breadboard for the FLiP Try-it Kit (#700-32023)
  • (1) – Propeller FLiP Microcontroller Module (#32123)
  • (1) – 4×4 Matrix Membrane Keypad (#27899)
  • (1) – Piezo Speaker (#900-00001)
  • (1) – 7-Segment LED (#350-00027)
  • (8) – 1 kΩ Resistors (brown-black-red)
  • (4) – 10 kΩ Resistors (brown-black-orange)
  • (4) – 220 Ω Resistors (red-red-brown)
  • Misc Jumper Wires

Pin Connections

  • P0 – P7: 4×4 Matrix Membrane Keypad
  • P8 – P15: 7-segment LED
  • P25: Piezo speaker

 

Circuit

Build the circuits shown below, following the wiring diagram and schematics.

Wiring

Schematics

Double-check to make sure the correct resistors are used. 1 kΩ resistors for the seven-segment display, 10 kΩ resistors for the grounded pins on the 4×4 matrix keypad, and 220 Ω resistors for the P0-P3 I/O pin keypad connections.

Testing and Programming

The best way to program this project is in three pieces:

  1. Test the 4×4 matrix keypad alone using the example Blockly code.
  2. Test the 7-segment display alone using the example Blockly code.
  3. If both of the above were successful, program the entire project!  
  • Download the 4×4 Matrix Keypad Test code below, then open and run it with BlocklyProp Solo.

Project8624-4×4-Matrix-Keypad-Test.svg

  • To make sure every part is working separately before synthesizing all of it, run the main loop with the keyNumber variable. This will ensure that the 4×4 matrix keypad is wired correctly and working as intended. Below is an example of what the terminal should display – in this case the number 9 is being pressed.

Next, test the seven-segment display by loading the Blockly code for the Seven-Segment Display Test:

Project8621-Seven-Segment-Test.svg

 

This will cycle through numbers 0-9 in an endless loop.

If the 4×4 matrix keypad and seven-segment display codes worked successfully, then you’re ready to run the Blockly code for the 4×4 Matrix Keypad with Seven-Segment Display (shown in full below):

Project8331-4×4-Keypad-7-Seg-Display.svg

Personalize the Code

First, let’s look at how it actually works. Then, we’ll give some suggestions for how you could make this project better suit your needs.

 

How it Works

The program initializes the 4×4 matrix keypad using the FLiP module’s first eight pins (P0-P8). It also sets the states of the seven-segment display pins to outputs, while attaching a binary value of 11111111. Next, the code enters an infinite repeat loop containing a variable called keyNumber that gets updated every pass through the loop. Three individual functions are also run every time through the loop: terminalPrint, checkKey, and beep.

The terminal displays the value from the keypad as -1 if nothing is pressed, or a value ranging from 0-15 if being pressed (depending on which button you are pressing). The checkKey function receives a decimal value from the keypad then set the states of all pins from 8 to 15 to the corresponding binary value. If nothing is pressed, all pins are turned off by making them low (a binary value of 00000000). The “beep” function makes a sound for a half second every time a button is pressed when the value of “keyNumber” greater than or equal to 0.

 

Try This

Make some modifications to the project to make it work more effectively. Try the following:

  • Change the pause block values to see what effect this has on the program. Try shorter or longer values.
  • Add a red LED to show when a button has been pressed. The BlocklyProp Build LED Circuits tutorial provides an example.
  • Modify the sound played back to be different for each button press. An example of this may be setting the frequency of the speaker to the variable value times 50:

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024


Source URL:https://learn.parallax.com/courses/4x4-keypad-with-7-segment-led/
Links