I am trying to adapt a alarm clock sketch that used external buttons, but I would like to utilize a LCD Keypad Shield. The data sheet says all the buttons are on pin A0, so every button is "set time" in the original sketch.
After reading this post
I found the values when I press each button, :
Right 0
Up 100
Down 257
Left 410
Select 640
and have tried to define them by modifying the existing code:
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Arduino pins to lcd
#define bt_time A0
#define bt_up A1
#define bt_down A2
#define bt_alarm A3
With:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Arduino pins to lcd
int lcd_key = 0;
int adc_key_in = 0;
#define bt_time 0
#define bt_up 1
#define bt_down 2
#define bt_alarm 3
#define buzzer 10
int read_LCD_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
if (adc_key_in < 50) return bt_time;
if (adc_key_in < 150) return bt_up;
if (adc_key_in < 307) return bt_down;
if (adc_key_in < 690) return bt_alarm;
}
I got this from here
It doesn't work.... when you press the buttons nothing happens.
It up loads with no errors, but the buttons don't do anything.
Please help, your my only hope.
Edit: The linked "Real_Time_Clock_With_Alarm.ino" is the source file, all I have changed is the above code. It works except I can't interact with it... because no buttons.... I have also tested the hardware with other sketch and it works as expected.
analogRead(0)
... is that same as analogRead(A0)?A0
and0
.< 307
and then< 690
but two of your observed readings 410 and 640 sit between these numbers.