Professional Documents
Culture Documents
h>
LiquidCrystal lcd(12,13,8,9,10,11);
panel
btnRIGHT
btnUP
btnDOWN
btnLEFT
btnSELECT
btnNONE
0
1
2
3
4
5
int read_LCD_buttons(){
adc_key_in = analogRead(0);
// 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 l
ikely result
if (adc_key_in > 1000) return btnNONE;
//
if
if
if
if
if
For V1.1 us
(adc_key_in
(adc_key_in
(adc_key_in
(adc_key_in
(adc_key_in
this threshold
< 50) return
< 250) return
< 450) return
< 650) return
< 850) return
btnRIGHT;
btnUP;
btnDOWN;
btnLEFT;
btnSELECT;
return btnNONE;
btnRIGHT;
btnUP;
btnDOWN;
btnLEFT;
btnSELECT;
// when all others fail, return this.
}
void setup(){
lcd.begin(16, 2);
// start the library
lcd.setCursor(0,0);
// set the LCD cursor position
lcd.print("Push the buttons"); // print a simple message on the LCD
}
void loop(){
lcd.setCursor(9,1);
s over
lcd.print(millis()/1000);
lcd.setCursor(0,1);
lcd_key = read_LCD_buttons();
switch (lcd_key){
erform an action
case btnRIGHT:{
the screen
lcd.print("RIGHT ");
delay(1000);
break;
}
case btnLEFT:{
lcd.print("LEFT ");
he screen
delay(1000);
break;
}
case btnUP:{
lcd.print("UP
");
screen
delay(1000);
break;
}
case btnDOWN:{
lcd.print("DOWN ");
he screen
delay(1000);
break;
}
case btnSELECT:{
lcd.print("SELECT");
the screen
delay(1000);
break;
}
case btnNONE:{
lcd.print("NONE ");
break;
}
}
}