miklik

Key Grag - DFRobot

Mar 11th, 2018
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <Arduino.h>
  2.  
  3. /*
  4. DFRobot LCD Shield for Arduino
  5. Key Grab v0.2
  6. Written by Glendon Klassen // Modified A0 values by Martin Mikala for old shield
  7. http://www.sourceforge.net/users/ecefixer
  8. http://ecefixer.tumblr.com
  9.  
  10. Displays the currently pressed key on the LCD screen.
  11.  
  12. Key Codes (in left-to-right order):
  13.  
  14. None   - 0
  15. Select - 1
  16. Left   - 2
  17. Up     - 3
  18. Down   - 4
  19. Right  - 5
  20.  
  21. */
  22.  
  23. #include <LiquidCrystal.h>
  24. #include <DFR_KeyMM.h>
  25.  
  26. //Pin assignments for DFRobot LCD Keypad Shield
  27. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  28. //---------------------------------------------
  29.  
  30. //DFR_KeyMM keypad(A0);
  31. DFR_KeyMM keypad;
  32.  
  33. int localKey = 0;
  34. String keyString = "";
  35.  
  36. void setup()
  37. {
  38.   lcd.begin(16, 2);
  39.   lcd.clear();
  40.   lcd.setCursor(0, 0);
  41.   lcd.print("Key Grab v0.2");
  42.   delay(2500);
  43.  
  44.   /*
  45.   OPTIONAL
  46.   keypad.setRate(x);
  47.   Sets the sample rate at once every x milliseconds.
  48.   Default: 10ms
  49.   */
  50.   keypad.setRate(10);
  51.  
  52. }
  53.  
  54. void loop()
  55. {
  56.   /*
  57.   keypad.getKey();
  58.   Grabs the current key.
  59.   Returns a non-zero integer corresponding to the pressed key,
  60.   OR
  61.   Returns 0 for no keys pressed,
  62.   OR
  63.   Returns -1 (sample wait) when no key is available to be sampled.
  64.   */
  65.   localKey = keypad.getKey();
  66.  
  67.   if (localKey != SAMPLE_WAIT)
  68.   {
  69.     lcd.clear();
  70.     lcd.setCursor(0, 0);
  71.     lcd.print("Current Key:");
  72.     lcd.setCursor(0, 1);
  73.     lcd.print(localKey);
  74.     lcd.print(" ");
  75.     lcd.print(keypad.getValue());
  76.   }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment