Skip to content

Instantly share code, notes, and snippets.

@rafamaciel
Created August 4, 2015 22:18
Show Gist options
  • Save rafamaciel/29c94c80ecfa7c841af9 to your computer and use it in GitHub Desktop.
Save rafamaciel/29c94c80ecfa7c841af9 to your computer and use it in GitHub Desktop.
Arduino LCD
/*
1602 LCD Keypad Shield Example Code using the LiquidCrystal Library
Library originally added 18 Apr 2008 by David A. Mellis
library modified 5 Jul 2009 by Limor Fried
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
modified Jan 2013 for the 1602 LCD Keypad Shield
by Bentley Born
This example code is in the public domain.
http://arduino.cc/en/Tutorial/LiquidCrystalDisplay
*/
// include the library code:
#include <LiquidCrystal.h>
int x = 0;
int currx = 1023;
String btnStr = "None";
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Analog 0: ");
lcd.print(currx);
lcd.setCursor(0,1);
lcd.print(btnStr);
}
void loop() {
x = analogRead(A0); // the buttons are read from the analog0 pin
// Check if x has changed
if ((x != 1023) && (x != currx)){
//update screen and change currx
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print(x);
currx = x;
if (currx > 740 && currx < 745){
btnStr="Select";
} else if (currx > 500 && currx < 510){
btnStr="Left";
} else if (currx < 10){
btnStr="Right";
} else if (currx > 140 && currx < 150){
btnStr="Up";
} else if (currx > 320 && currx < 365){
btnStr="Down";
}
//update button pressed
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(btnStr);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment