Hello,
I am trying to enter two variables via LCD Shield up/down and select buttons.
The first one is ok but when I am trying to input the second one,
I want it to go to the second label when I press the Select buttun
I guess I am using the GOTO function wrong
(I am using it as I remember from the BASIC programming days)
Can you pleas help?
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
int read_LCD_buttons()
{
adc_key_in = analogRead(0);
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;
}
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
YS: //*********1.Label
lcd_key = read_LCD_buttons();
static int YS = 0;
if(lcd_key == 1)
{
YS = constrain(YS+1,-0,120);
}
else if (lcd_key == 2)
{
YS = constrain(YS-1,0,120);
}
else if (lcd_key == 4) // ***********If pressed this button go to label SS
{
goto SS;
}
lcd.setCursor(0,0);
lcd.print(" Y - S ");
lcd.setCursor(3,1);
if (YS < 100)
lcd.print(' ');
if (YS < 10)
lcd.print(' ');
lcd.print(YS);
lcd.setCursor(8,1);
lcd.print("sec ");
delay(50);
SS: //**********2.Label
static int SS = 0;
if(lcd_key == 1)
{
SS = constrain(SS+1,-0,120);
}
else if (lcd_key == 2)
{
SS = constrain(SS-1,0,120);
}
lcd.setCursor(0,0);
lcd.print(" S - S ");
lcd.setCursor(3,1);
if (YS < 100)
lcd.print(' ');
if (YS < 10)
lcd.print(' ');
lcd.print(YS);
lcd.setCursor(8,1);
lcd.print("min ");
delay(50);
}