int pushbutton = 11;// connect output to push button
int led = 12;// Connected to relay (LED)
int ledstate=0;
int buttonState;
int previousbuttonState=0;
void setup() {
Please read the post at the start of any forum , entitled "How to use this Forum".
This will help with advice on how to present your code and problems.
Can you post a circuit diagram of your project please?
Just an image of a drawn diagram will be fine.
Please include power supplies, component names and pin labels.
Hello ibrahimet
The IDE provides an example called State change detection
You may use this example to control the LEDs.
Have a nice day and enjoy coding in C++.
This will not print anything because led is equal to 12, not HIGH or LOW. You probably meant to use ledstate. I would recommend always using HIGH and LOW rather than 0 and 1 for digital inputs and outputs.
if (led == HIGH) {
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("LED IS ON");
}
else {
(led == LOW);
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("LED IS OFF");
}
It will print "LED IS OFF" every time because there is no "if" after the else and because led = 12 as you said. The bare (led == LOW) will apply the comparison operator, determine it to be 0 and then discard it because there isn't a LHS variable to assign it to or an if statement to use it for a branch, if the compiler doesn't optimize it away altogether.