// read the buttons from LCD keypad shield
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, 131, 307, 481, 722
// we add approx 50 to those values and check to see if we are close
// No button pressed should be 1023
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void timedCountDown(int secondCount, char countLabel[])
{
long seconds = 0;
long minutes = 0;
lcdClear();
lcd.print(countLabel);
for (int i = secondCount; i >= 0; i--)
{
seconds = i;
minutes = i / 60;
if (minutes > 0)
{
seconds = seconds - (minutes * 60);
}
if (minutes > 0)
{
lcd.setCursor(0,1);
lcd.print(minutes);
lcd.print(" min ");
}
else
{
lcd.setCursor(0,1);
}
if (seconds < 10) lcd.print("0");
lcd.print(seconds);
lcd.print(" sec remaining");
if (seconds > 0) delay(1000);
if (read_LCD_buttons() == btnSELECT) //cancel
{
timerCancelled("Timer");
i = 0;
return;
}
}
lcd.setCursor(6,1);
timedBeep(longBeep,3);
}
// Pass maxCount to getTimerMinutes
int getTimerMinutes(char timerText[], int startNum, int maxCount)
{
int minutes = startNum;
int button = 0;
lcdClear();
lcd.print(timerText);
lcd.setCursor(0,1);
lcd.print(minutes);
while (button != btnSELECT)
{
button = read_LCD_buttons();
Serial.println(button);
void timedBeep(int beepTime, int beepCount)
{
for (int i = 0; i < beepCount; i ++)
{
digitalWrite(beeper, HIGH);
delay(beepTime);
digitalWrite(beeper, LOW);
delay(beepTime);
}
}