hi can anyone help me with this.
I'm trying to get my lcd screen to show different messages when i press different a button.
eg... if i press button 1 the lcd shows "hi" and if i press button 2 it shows "bye" but if no buttons are pressed it shows "press a button.
now it'll show "press a button" but when i press one nothing happens.
i'm using the if and else commands but its not changing when any buttons are pressed.
Where am i going wrong can anyonw please help as i'm new to this and trying my best to understand all the different commands.
hi can anyone help me with this.
Without seeing your code?
You've got to be joking.
The problem is probably in line 5, or maybe 17.
No. Wait a minute. You have not posted your code, have you, nor have you described or provided a diagram of how your buttons are wired, so who knows.
The stickies at the top of this forum will give you advice on how to post your code using code tags.
Post your code and you will get plenty of advice.
okay i've changed something and it's not picking up the first if command but i'll work that out.
Here's the code..
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int but1 = 6;
int but2 = 7;
void setup () {
lcd.begin(16,2);
lcd.clear ();
pinMode (but1,INPUT);
pinMode (but2,INPUT);
lcd.print(" Drive Speak ");
delay(4000);
}
void loop (){
if (digitalRead (but1)= HIGH && digitalRead (but2)= LOW);{
lcd.setCursor(0,1);
lcd.clear();
lcd.print(" THANKYOU ");
}
else if{
(digitalRead (but2 = HIGH)&& digitalRead (but1=LOW));
lcd.setCursor(0,1);
lcd.clear();
lcd.print(" NOT NICE ");
lcd.setCursor(1,2);
lcd.print(" DRIVER ");
}
else {
lcd.setCursor(1,1);
lcd.clear();
lcd.print(" Please Drive ");
lcd.setCursor(1,2);
lcd.print(" CAREFULLY ");
}
}
if (digitalRead (but1)= HIGH && digitalRead (but2)= LOW);{
Two basic errors in one line.
"==" not "=" and no semicolon
thank-you i'll change that line
I've not had my board long so it's all new to me but if i dont ask i'll never know.
Again thank-you
else if{
(digitalRead (but2 = HIGH)&& digitalRead (but1=LOW));
The code layout is bizarre and is masking the problem with the extraneous semi-colon and the erroneous use of brackets/braces. Look at the structure of the if/else if and the use of braces and brackets very carefully.
i have now removed the semi-colon and sorted the brackets out now.
Again thank-you I'm not getting the error now
digitalRead (but2 = HIGH)
Very wrong too.
Some suggestions on the code layout
Put each opening and closing brace on its own line
Each while or if test has a pair of braces enclosing the code to be executed even if there is only one statement
Remove extra blank lines. I usually leave a blank line between function sections of code and between functions
Use Auto-Format from the IDE menu.
Others may have different standards but these work for me.
Thank-you for all your help i see where i went wrong and got it working perfectly.
I've removed some useless parts to the code and it looks better too XD.
I would of been scratching my head untill it was bald ha ha.
Again thank-you everyone :).