- /*
- LiquidCrystal Library - Hello World
- Demonstrates the use a 16x2 LCD display. The LiquidCrystal
- library works with all LCD displays that are compatible with the
- Hitachi HD44780 driver. There are many of them out there, and you
- can usually tell them by the 16-pin interface.
- This sketch prints "Hello World!" to the LCD
- and shows the time.
- The circuit:
- * LCD RS pin to digital pin 12
- * LCD Enable pin to digital pin 11
- * LCD D4 pin to digital pin 5
- * LCD D5 pin to digital pin 4
- * LCD D6 pin to digital pin 3
- * LCD D7 pin to digital pin 2
- * LCD R/W pin to ground
- * LCD VSS pin to ground
- * LCD VCC pin to 5V
- * 10K resistor:
- * ends to +5V and ground
- * wiper to LCD VO pin (pin 3)
- Library originally added 18 Apr 2008
- by David A. Mellis
- library modified 5 Jul 2009
- by Limor Fried (http://www.ladyada.net)
- example added 9 Jul 2009
- by Tom Igoe
- modified 22 Nov 2010
- by Tom Igoe
- modified 7 Nov 2016
- by Arturo Guadalupi
- This example code is in the public domain.
- http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
- */
- int lcd_key=0;
- int adc_key_in=0;
- #define btnRIGHT 0
- #define btnUP 1
- #define btnDOWN 2
- #define btnLEFT 3
- #define btnSELECT 4
- #define btnNONE 5
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library by associating any needed LCD interface pin
- // with the arduino pin number it is connected to
- const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- const int numCols=16;
- const int numRows=2;
- void setup() {
- // set up the LCD's number of columns and rows:
- lcd.begin(numCols,numRows);
- // Print a message to the LCD.
- lcd.setCursor(0,0);
- }
- int x1=0;
- int y1=0;
- int read_LCD_buttons(){ // read the buttons
- adc_key_in = analogRead(0); // read the value from the sensor
- // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
- // we add approx 50 to those values and check to see if we are close
- // We make this the 1st option for speed reasons since it will be the most likely result
- if (adc_key_in > 1000) return btnNONE;
- // For V1.1 us this threshold
- if (adc_key_in < 50) return btnRIGHT;
- if (adc_key_in < 250) return btnUP;
- if (adc_key_in < 450) return btnDOWN;
- if (adc_key_in < 650) return btnLEFT;
- if (adc_key_in < 850) return btnSELECT;
- return btnNONE;
- }
- void loop() {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd_key=read_LCD_buttons();
- switch (lcd_key) // depending on which button was pushed, we perform an action
- {
- case btnRIGHT:
- {
- x1+=1;
- lcd.clear();
- lcd.setCursor(x1,y1);
- lcd.print("*");
- delay(500);
- break;
- }
- case btnLEFT:
- {
- x1-=1;
- lcd.clear();
- lcd.setCursor(x1,y1);
- lcd.print("*");
- delay(500);
- break;
- }
- case btnUP:
- {
- y1+=1;
- lcd.clear();
- lcd.setCursor(x1,y1);
- lcd.print("*");
- delay(500);
- break;
- }
- case btnDOWN:
- {
- y1-=1;
- lcd.clear();
- lcd.setCursor(x1,y1);
- lcd.print("*");
- delay(500);
- break;
- }
- case btnSELECT:
- {
- break;
- }
- case btnNONE:
- {
- // lcd.print(DropCount);
- break;
- }
- }
- }