lcd.clear(); does not work

I use liquidCrystal.h as LCD library
and analog input to recognize which button is pressed. The code:

int setPinValue;
int parameter;
if((setPinValue>=240)&&(setPinValue<420)) //"Down" button pressed
{lcd.clear(); parameter--;}

Why after pressing the button the rubbish from previous screen is still there? After pressing second time it disappears. What is wrong?
Wal

int setPinValue;
int parameter;
if((setPinValue>=240)&&(setPinValue<420)) //"Down" button pressed
{lcd.clear(); parameter--;}

Where does setPinValue get valued? Where does parameter get valued? This code snippet does not provide enough information.

Your topic says "lcd.clear() doesn't work", but it looks more like it ought to say "lcd.clear() doesn't work because I don't call it".

Not to mention that I was wondering why, just out of curiosity, you are using an analog input for button presses?

So he could tell if the button was pressed part way, I guess.

You're joking, right? Button means on or off, in my book!
[edit]absent the debouncing, of course[/edit]

So he could tell if the button was pressed part way, I guess.

I didn't know a button could be partially pressed..... :-/

" Where does setPinValue get valued? Where does parameter get valued? This code snippet does not provide enough information.

Your topic says "lcd.clear() doesn't work", but it looks more like it ought to say "lcd.clear() doesn't work because I don't call it".
Back to top "

Thank You for the answers.
I bought a board with LCD and with 5 buttons already soldered to the analog input A0, int setPinValue is the value on the input. Voltage on the pin depends on which button is pressed. There are some parameters in the program, each parameter has a value. Using "up" and "down" buttons a parameter is chosen at first, then press "select" button and the value of the chosen parameter can be changed with the buttons.
Actually it works, but with rubbish from the previous screen. plus expected information.

int setPinValue is the value on the input. Voltage on the pin depends on which button is pressed.

No, "int setPinValue" is not the value of the input.

int buttonPin = 3;
int setPinValue = digitalRead(buttonPin);

Execute this code, and setPinValue will contain a value that is defined by whether the voltage on pin 3 is above or below Vref/2.

Your code snippet did not show how setPinValue got a value. It also did not show haw parameter got a value.

If you want help here, you need to post more of your code. No body is going to make fun of you for having mistakes in your code. We assume that there are mistakes in the code, or you wouldn't have come here for help.

Either the problem is in your code, in the hardware (the way the stuff is wired up), or in your expectations of what the hardware is supposed to do, with respect to the software.

What board do you have that has a button soldered to an analog input? Digital input is for either/or devices like switches (buttons) that are either on or off. Analog input is for devices that can report multiple values, like temperature sensors, potentiometers, etc.

Hi Paul. Because of size, the all programm was not shown.
More details now:
int Value;//value of parameter
int Value_change;//value of In- or Decrement
int setPin=0;//buttons connected to A0 pin of Arduino
int i;//to calculate how long the "select" button is pressed
int j;//to calculate how long no actions took place
int setPinValue;//value of analog input
boolean Program_Mode;
boolean Value_Mode;
//further code

void loop()
{
setPinValue = analogRead(setPin);
if ((setPinValue>=240)&&(setPinValue<420))//"Down" button pressed
{
lcd.clear();delay(20); j=0;
if ((Program_Mode==HIGH)&&(Value_Mode==HIGH))
{Value-=Value_change;}//decrement value of the paramerer chosen
else {parameter--;}//decrement parameter's number
}
//further code

}//end of void loop()

I think, then, that you need to create a much smaller sketch that illustrates the problem, or makes it go away. There is so much that is not shown here.

You still have not addressed the hardware questions.

But, since I AM trying to help, I'd add a Serial.print statement after the analogRead function call, to see what you actually read.

If you have a switch attached to the pin, and you have defined the pin as an INPUT pin, the voltage at the pin is NOT variable. It's either 0 or Vref. Nothing in between. Since you are assuming that the value can be somewhere in between, and only clearing the screen if it is, I still think that the reason that lcd.clear() doesn't work is because it isn't called.

Pictures, please. Or at least a link to the hardware you have.

The board was bought in the Internet, specially desighned for Arduino.
similar to this: http://cgi.ebay.co.uk/Arduino-LCD-Keypad-Shield_W0QQitemZ220513220104QQcmdZViewItemQQptZUK_ToysGames_RadioControlled_JN?hash=item33579cb608
6 digital I/O used for LCD control 1 analog input for 5 buttons.
Actually, the value of the analog pin is variable, to locate the button pressed.

When a value of parameter 1 is (for example) is 300 and the value of parameter 0 is 6, after transition from parameter 1 to parameter 0, the display shows: 600. When the "Down" button pressed again (where is nothing below zero) the display shows the correct value: 6.
I read somewhere, that it takes about 100usec for analog reading. May be a delay about 1mSec after analog reading could fix the problem?

OK. Now I understand why the analogRead is required. The hardware is collecting all the button states into one value.

The analogRead does take time. Adding more time, using delay(), won't help.

So, did you add a Serial.print (or Serial.println) after the digitalRead?

What value did you get when the "Down" button was pressed?

Thank You Paul. I will try it tonight.

I put line after analog reading
int b =79;
serial.print(b);
it did not change anything

after that I put another line:
lcd.setCursor(0,0);
lcd.print(" ";
nothing changed as well.

after that I added a new variable:
boolean lcd_clear=LOW;

//further code...
void loop()
{
if(lcd_clear==LOW){lcd.clear();lcd_clear=HIGH;}

//further code...
setPinValue = analogRead(setPin);
if ((setPinValue>=240)&&(setPinValue<420))//"Down" button pressed
{
if ((Program_Mode==HIGH)&&(Value_Mode==HIGH))
{Value-=Value_change;}//decrement value of the paramerer chosen
else {parameter--;}//decrement parameter's number

lcd_clear=LOW;//this line was extra added
}
//further code

}//end of void loop()

The problem disappeared. Have no idea, why it did not work originally?
Can somebody explain it?

I put line after analog reading
int b =79;
serial.print(b);
it did not change anything

Of course not. The idea was to print the value read from the sensor (switches).

You still have no idea what value is being returned by the analogRead function. So, you still have no idea whether the block of code after the if test after the analogRead (where you call lcd.clear()) is being executed.

after that I put another line:
lcd.setCursor(0,0);
lcd.print(" ";
nothing changed as well.

Well, of course not. You still aren't calling lcd.clear().

after that I added a new variable:
boolean lcd_clear=LOW;

if(lcd_clear==LOW){lcd.clear();lcd_clear=HIGH;}

So, NOW you're calling lcd.clear(), and the screen clears. And you wonder why?

Hi Paul. Thank You for the comments.
Why in this code the lcd.clear(); is not being called:

void loop()
{
setPinValue = analogRead(setPin);
if ((setPinValue>=240)&&(setPinValue<420))//"Down" button pressed
{
lcd.clear();delay(20); j=0;
if ((Program_Mode==HIGH)&&(Value_Mode==HIGH))
{Value-=Value_change;}//decrement value of the paramerer chosen
else {parameter--;}//decrement parameter's number
}
//further code

}//end of void loop()

? What is wrong?

void loop()
{
   setPinValue = analogRead(setPin);

   // Add these two lines 
   Serial.print("setPinValue = ");
   Serial.println(setPinValue, DEC);

   if ((setPinValue>=240)&&(setPinValue<420))//"Down" button pressed
   {
      lcd.clear();delay(20); j=0;
      if ((Program_Mode==HIGH)&&(Value_Mode==HIGH))
      {
          Value-=Value_change; //decrement value of paramerer chosen
      }
      else
      {
          parameter--;//decrement  parameter's number
      }
   }
//further code

}//end of void loop()

Add the two lines shown above, and "Serial.begin(9600);" to setup, if there is not already a similar statement there. Compile and upload. Then, open the Serial Monitor window.

Push the buttons, and watch the values printed change.

The most likely reason that lcd.clear() is not being called is that teh value in setPinValue is NOT between 240 and 420.

Prove to yourself, and me, that it IS (or, more likely, isn't). Change, if needed, the range of values that enable the following code to execute.

Thank You Paul, I''ll try it tonight.
Not clear, if setPinValue is not between 240 and 420, why after pressing "Down" button the parameter or parameter's value decrement as expected? It was clearly shown on LCD.

You keep posting bits and pieces of your code, and you'd like me to guess what's happening in the rest of it. No thank you.

As Paul says you haven't posted the complete code so we are all just guessing, but from what we have being given in you original code;
lcd.clear is called when "the down button has been pressed"
and
Value and parameter are changed when "Program_Mode and Value_Mode are HIGH"
Although it does look like it is in the if loop that calls lcd.clear (?). To get the best results from the forum, post the whole code (and use indenting) using the code button, i.e.

int Value;//value of parameter
int Value_change;//value of In- or Decrement
int setPin=0;//buttons connected to A0 pin of Arduino
int i;//to calculate how long the "select" button is pressed
int j;//to calculate how long no actions took place
int setPinValue;//value of analog input
boolean Program_Mode;
boolean Value_Mode;
//further code

void loop()
{
setPinValue = analogRead(setPin);
if ((setPinValue>=240)&&(setPinValue<420))//"Down" button pressed
{
lcd.clear();delay(20); j=0;
if ((Program_Mode==HIGH)&&(Value_Mode==HIGH))
{Value-=Value_change;}//decrement value of the paramerer chosen
else {parameter--;}//decrement  parameter's number
}
//further code

}//end of void loop()