Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- /*
- DFRobot LCD Shield for Arduino
- Key Grab v0.2
- Written by Glendon Klassen // Modified A0 values by Martin Mikala for old shield
- http://www.sourceforge.net/users/ecefixer
- http://ecefixer.tumblr.com
- Displays the currently pressed key on the LCD screen.
- Key Codes (in left-to-right order):
- None - 0
- Select - 1
- Left - 2
- Up - 3
- Down - 4
- Right - 5
- */
- #include <LiquidCrystal.h>
- #include <DFR_KeyMM.h>
- //Pin assignments for DFRobot LCD Keypad Shield
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- //---------------------------------------------
- //DFR_KeyMM keypad(A0);
- DFR_KeyMM keypad;
- int localKey = 0;
- String keyString = "";
- void setup()
- {
- lcd.begin(16, 2);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Key Grab v0.2");
- delay(2500);
- /*
- OPTIONAL
- keypad.setRate(x);
- Sets the sample rate at once every x milliseconds.
- Default: 10ms
- */
- keypad.setRate(10);
- }
- void loop()
- {
- /*
- keypad.getKey();
- Grabs the current key.
- Returns a non-zero integer corresponding to the pressed key,
- OR
- Returns 0 for no keys pressed,
- OR
- Returns -1 (sample wait) when no key is available to be sampled.
- */
- localKey = keypad.getKey();
- if (localKey != SAMPLE_WAIT)
- {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Current Key:");
- lcd.setCursor(0, 1);
- lcd.print(localKey);
- lcd.print(" ");
- lcd.print(keypad.getValue());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment