Keypad shield for the Arduino UNO
FunduinoPublished on
Display und sechs Taster ohne eine einzige Kabelverbindung
You need this
LCD Keypad Shield 1602 - 16x2 display, 5 buttons, for Arduino UNO
4,10 € *Item no. F23107306About the product — LCD Keypad Shield 1602 - 16x2 display, 5 buttons, for Arduino UNO
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
All 2 parts together 15,22 € *
* All prices include statutory VAT, plus shipping costs.
Material
What the keypad shield can do
Attach the shield
Which pins remain free
The program code
Sketch: Read the Keypad Shield buttons
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Specify the required pins
// Create some variables
int Taster = 0;
int Analogwert = 0;
#define Tasterrechts 0
#define Tasteroben 1
#define Tasterunten 2
#define Tasterlinks 3
#define Tasterselect 4
#define KeinTaster 5
// From here on, a new program block named "Tasterstatus" is created. It checks only which button is pressed.
int Tasterstatus()
{
Analogwert = analogRead(A0); // Read the buttons on analog pin A0.
if (Analogwert > 1000) return KeinTaster;
if (Analogwert < 50) return Tasterrechts;
if (Analogwert < 195) return Tasteroben;
if (Analogwert < 380) return Tasterunten;
if (Analogwert < 555) return Tasterlinks;
if (Analogwert < 790) return Tasterselect;
return KeinTaster; // Output when no button is pressed.
}
// End of the "Tasterstatus" program block.
void setup()
{
lcd.begin(16, 2); // Start the program library.
lcd.setCursor(0, 0); // Set the cursor to the top left.
lcd.print("Funduino GmbH"); // Display the text on the first line.
}
void loop()
{
lcd.setCursor(12, 1); // Move the cursor to position 12 in line 2 (0 = line 1, 1 = line 2).
lcd.print(millis() / 1000); // Display the seconds since the program started.
lcd.setCursor(0, 1); // Move the cursor to position 0 in line 2.
Taster = Tasterstatus(); // Here the loop jumps to the "Tasterstatus" section specified above and reads which button is pressed.
switch (Taster) // The following switch-case statement decides what is displayed on the LCD depending on which button is pressed.
{
case Tasterrechts: // If the right button was pressed ...
{
lcd.print("Right "); // ... this line appears. The spaces after the text ensure that the previous text on the line is cleared.
break;
}
case Tasterlinks: // If the left button was pressed ...
{
lcd.print("Left "); // ... this line appears, and so on.
break;
}
case Tasteroben:
{
lcd.print("Up ");
break;
}
case Tasterunten:
{
lcd.print("Down ");
break;
}
case Tasterselect:
{
lcd.print("SELECT ");
break;
}
case KeinTaster:
{
lcd.print("No button ");
break;
}
} // End switch-case statement
} // End loop3D-printed enclosure
Rate the instructions