Advertisement
tiodocomputador

Teste LCD Keypad Shield

Apr 19th, 2014
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. /*
  2.   1602 LCD Keypad Shield Example Code using the LiquidCrystal Library
  3.  
  4.  Library originally added 18 Apr 2008 by David A. Mellis
  5.  library modified 5 Jul 2009 by Limor Fried
  6.  example added 9 Jul 2009
  7.  by Tom Igoe
  8.  modified 22 Nov 2010
  9.  by Tom Igoe
  10.  modified Jan 2013 for the 1602 LCD Keypad Shield
  11.  by Bentley Born
  12.  
  13.  This example code is in the public domain.
  14.  
  15.  http://arduino.cc/en/Tutorial/LiquidCrystalDisplay
  16.  
  17.  */
  18.  
  19. // include the library code:
  20. #include <LiquidCrystal.h>
  21.  
  22. int x = 0;
  23. int currx = 1023;
  24. String btnStr = "None";
  25.  
  26. // initialize the library with the numbers of the interface pins
  27. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  28.  
  29. void setup() {
  30.   // set up the LCD's number of columns and rows:
  31.   lcd.begin(16, 2);
  32.   // Print a message to the LCD.
  33.   lcd.clear();
  34.   lcd.setCursor(0,0);
  35.   lcd.print("Analog 0: ");
  36.   lcd.print(currx);
  37.   lcd.setCursor(0,1);
  38.   lcd.print(btnStr);
  39. }
  40.  
  41. void loop() {
  42.  
  43.   x = analogRead(A0); // the buttons are read from the analog0 pin
  44.  
  45.   // Check if x has changed
  46.   if ((x != 1023) && (x != currx)){
  47.  
  48.     //update screen and change currx
  49.     lcd.setCursor(10,0);
  50.     lcd.print("     ");
  51.     lcd.setCursor(10,0);
  52.     lcd.print(x);
  53.     currx = x;
  54.    
  55.     if (currx > 740 && currx < 745){
  56.    
  57.        btnStr="Select";
  58.    
  59.     } else if (currx > 500 && currx < 510){
  60.    
  61.       btnStr="Left";
  62.      
  63.     } else if (currx < 10){
  64.    
  65.       btnStr="Right";
  66.      
  67.     } else if (currx > 140 && currx < 150){
  68.    
  69.       btnStr="Up";
  70.      
  71.     } else if (currx > 320 && currx < 365){
  72.    
  73.       btnStr="Down";
  74.      
  75.     }
  76.    
  77.       //update button pressed
  78.       lcd.setCursor(0,1);
  79.       lcd.print("        ");
  80.       lcd.setCursor(0,1);
  81.       lcd.print(btnStr);
  82.   }
  83.  
  84.   delay(10);
  85.    
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement