Thank you for your quick answer.
I am trying to enter the number of frames for a time lapse rail.
So the "value" print right with Serial.print but when I try to print it to LCD the value is now 0000
I tried to declare a second char array as you suggested and get the same result.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
enum {btnNONE, btnSELECT, btnLEFT, btnUP, btnDOWN, btnRIGHT, NUM_KEYS };
const byte ButtonsPin= A0;
int read_LCD_buttons()
{
int returnValue;
// read ADC value of pressed button
int adc_key_in = analogRead (ButtonsPin);
int adc_key_in1= analogRead (ButtonsPin);
// read again and check for stable ADC reading (software debouncing for analog input)
if (abs(adc_key_in1-adc_key_in)>3) return btnNONE; // if ADC reading is not stable, return btnNONE
if (adc_key_in <50) returnValue= btnRIGHT;
else if (adc_key_in <150) returnValue= btnUP;
else if (adc_key_in <325) returnValue= btnDOWN;
else if (adc_key_in <500) returnValue= btnLEFT;
else if (adc_key_in <800) returnValue= btnSELECT;
else returnValue=btnNONE;
// simple "blocking" code: "Busy waiting" until button is released by user
while(adc_key_in<800) adc_key_in= analogRead(ButtonsPin);
return returnValue;
}
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.print ("How many frame?");
lcd.blink();
}
char value[]= "0000";
int cursorPos;
boolean lcdNeedsUpdate=true;
void loop()
{
char key=read_LCD_buttons();
if (key!= btnNONE) lcdNeedsUpdate=true;
switch (key)
{
case btnRIGHT:
if (cursorPos<3) cursorPos++;
break;
case btnLEFT:
if (cursorPos>0) cursorPos--;
break;
case btnUP:
if (value[cursorPos]<'9') value[cursorPos]++;
break;
case btnDOWN:
if (value[cursorPos]>'0') value[cursorPos]--;
break;
case btnSELECT:
Serial.print("Saved value: ");
Serial.println(value);
strcpy(value,"0000");
cursorPos=0;
lcd.clear();
lcd.setCursor(0,1);
lcd.print (value);
break;
}
if (lcdNeedsUpdate)
{
lcd.setCursor(0,1);
lcd.print(value);
lcd.setCursor(cursorPos,1);
lcdNeedsUpdate=false;
}
}
How can I keep the "value" recorded? Your help if much appreciated!