I want to hold 4 different numbers in EEPROM when a user selects it.
My project is on an LCD shield where a user will use the (up/down) buttons to select a number and then (select) to select it.
I wanted a loop in a loop so that the program will wait for the user to select the number before moving on. At the moment the program is running everything at once at it makes a mess on my display.
This is the code.
#include <EEPROM.h>
//Using LiquidCrystal library
#include <LiquidCrystal.h>
/*******************************************************
This program will add a value and display it. To increment
use the UP and DOWN button.
*******************************************************/
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
int Machine = 0;
int CONC = 0;
int DESVOL = 0;
int CURVOL = 0;
#define btnUP 1
#define btnDOWN 2
#define btnSELECT 3
// declair funtion to read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// For V1.1 us this threshold
/*
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
*/
// For V1.0 comment the other threshold and use the one below:
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 790) return btnSELECT;
}
void setup()
{
lcd.begin(16, 2); // start the library
Serial.begin(9600);
}
void loop()
{
lcd.clear();
{
lcd.setCursor(0,0);
lcd.print("Welcome to FSG");
delay(3000);
lcd.clear();
(lcd_key = read_LCD_buttons());
static int value1 = 1;
if (lcd_key == 1)
{
value1 = constrain(value1 + 1, 1, 7); // I only wanted it to count from (-30)-(+30) and back
}
else if (lcd_key == 2)
{
value1 = constrain(value1 - 1, 1, 7); // I only wanted it to count from (-30)-(+30_)and back
}
lcd.setCursor(0, 0);
lcd.print("Select Machine: ");
lcd.setCursor(0, 3);
lcd.print(value1); // displays the count
lcd.print(" "); //This space is here to clear the double digit area.
delay(150);
if(lcd_key ==3){
EEPROM.put(Machine,value1);
delay(300);
Serial.println(value1);
lcd.print("Done");
delay(500);
lcd.clear();
static int value2 = 1;
if (lcd_key == 1)
{
value2 = constrain(value2 + 1, 1, 30); // I only wanted it to count from (-30)-(+30) and back
}
else if (lcd_key == 2)
{
value2 = constrain(value2 - 1, 1, 30); // I only wanted it to count from (-30)-(+30_)and back
}
lcd.setCursor(0, 0);
lcd.autoscroll();
delay(100);
lcd.print("Select Current Concentration:");
lcd.setCursor(0, 3);
lcd.print(value2); // displays the count
lcd.print(" "); //This space is here to clear the double digit area.
delay(150);
}
}
}