Using an LCD Keypad Shield on an UNO

I'm trying to use an LCD keypad shield (in combination with some sensors) to make a Bio-Dome. I want the temperature and soil moisture to show on the LCD when the buttons are not being pushed. When the buttons are pushed I want them to change the "Set Temperature" and then "Set Moisture". The code I have now does what i want but i am having trouble with the delays. As soon as i let go of the buttons it goes back to the main screen, but i want to delay it for a couple seconds. Can anyone help?

CODE:

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
byte degree[8] = {
B01100,
B10010,
B10010,
B01100,
B00000,
B00000,
B00000,
B00000
};
int x;
int y;
int SensorPin = A1;
int SensorValue;
int Moisture;
int SetMoisture;
int TemperPin = A5;
int TemperValue;
int Temp;
int SetTemp;
int ledPin1 = 13;
int ledPin2 = 12;
int ledPin3 = 3;
int ledPin4 = 2;
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#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 > 1000) return btnNONE;
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;
}

void setup(){
pinMode(SensorPin, INPUT);
pinMode(TemperPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
lcd.begin(16, 2);
lcd.createChar(1, degree);
SensorValue = analogRead(SensorPin);
Moisture = (SensorValue/10);
TemperValue = analogRead(TemperPin);
Temp = (((TemperValue)));
}

void loop(){

//----------------------------------------------------------------
SetTemp = x;
SetMoisture = y;
lcd.createChar(1, degree);
lcd_key = read_LCD_buttons();
switch (lcd_key){
case btnRIGHT:{
y++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set Moisture: ");
lcd.print(y);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(100);
break;
}
case btnLEFT:{
y--;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set Moisture: ");
lcd.print(y);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
delay (100);
break;
}
case btnUP:{
x++;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set Temp: ");
lcd.print(x);
lcd.write(1);
lcd.print("F ");
lcd.setCursor(0,1);
lcd.print(" ");
delay (100);
break;
}
case btnDOWN:{
x--;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set Temp: ");
lcd.print(x);
lcd.write(1);
lcd.print("F ");
lcd.setCursor(0,1);
lcd.print(" ");
delay (100);
break;
}
case btnSELECT:{
break;
}
case btnNONE:{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(Temp);
lcd.write(1);
lcd.print("F ");
lcd.setCursor (0,1);
lcd.print("Moisture: ");
lcd.print(Moisture);
lcd.print(" ");
delay(100);
break;
}
}
//-----------------------------------------------------------
/* if ((Moisture)<= (SetMoisture-3)){
digitalWrite(ledPin1,HIGH);
delay (100);
}
else if ((Moisture)>= (SetMoisture-3)){
digitalWrite(ledPin1,LOW);
delay (100);
}
if ((Moisture)>= (SetMoisture+3)){
digitalWrite(ledPin2,HIGH);
delay (100);
}
else if ((Moisture)<= (SetMoisture+3)){
digitalWrite(ledPin2,LOW);
delay (100);
}
//---------------------------------------------------------------

if ((Temp)<= (SetTemp - 1)){
digitalWrite(ledPin3,HIGH);
delay (100);
}
else if ((Temp)>= (SetTemp - 1)){
digitalWrite(ledPin3,LOW);
delay (100);
}
if ((Temp)>= (SetTemp + 1)){
digitalWrite(ledPin4,HIGH);
delay (100);
}
else if ((Temp)<= (SetTemp + 1)){
digitalWrite(ledPin4,LOW);
delay (100);
} */

//---------------------------------------------------------------

}

BioDome2.ino (4.93 KB)

but i want to delay it for a couple seconds.

Then,

delay(100);

isn't long enough, is it?

the delay (100) is there to update the value. I want the LCD to stay at the "Set " screen for a couple seconds after i let go of the button.

I want the LCD to stay at the "Set " screen for a couple seconds after i let go of the button.

The, you need to make changes to the btnNONE case. Add a delay() before you clear the screen.

Yes I tried that and it works for delaying the set screen but i have to hold it down for 2 secs if i want it to change and if i go too far it takes 4 secs to go back the other way

but i have to hold it down for 2 secs

You shouldn't have to hold the LCD down at all. If you mean something else, do not use pronouns without referents.

In general, do not use delay(). Read, understand, and embrace the blink without delay philosophy.

Sorry for the misunderstanding. I meant the Buttons on the LCD display. I fixed that problem, now I have a new one. I'm trying to turn on an led for 1 secs and turn it off for 3 secs. I was trying to manipulate the blink but it didn't work. Help?

int ledState = LOW;
long previousMillis = 0;
long intervalLow = 3000;
long intervalHigh = 1000;
unsigned long currentMillis1 = millis();
unsigned long currentMillis2 = millis();
if (ledState == LOW) {
if (currentMillis1 - previousMillis > intervalLow) {
previousMillis = currentMillis1;
ledState = HIGH;
digitalWrite(solenoidWater, ledState);
}
}
else {
if (currentMillis2 - previousMillis > intervalHigh) {
previousMillis = currentMillis2;
ledState = LOW;
digitalWrite(solenoidWater, ledState);
}
}

  unsigned long currentMillis1 = millis();
  unsigned long currentMillis2 = millis();

Get real. You don't need two copies of now.

       ledState = HIGH;
       digitalWrite(solenoidWater, ledState);

There is nothing magic about the name ledState. It looks rather stupid, though, applied to a solenoid pin.

I was trying to manipulate the blink but it didn't work.

The code did something. You didn't explain what. You expected the code to do something. You didn't explain what. All that we can determine from "it didn't work" is that the two somethings are not the same thing.

Help?

Um, no. The ball's in your court.