I have an if statement that is supposed to set an led to high if the variables value is 1. However the if statement is somehow writing the variable to a 1 when it is declared globally as 0. I used serial to print the value and it once the if statement runs it switches the value to a 1.
Here is my code.
int led1 = 13; // pin connected to led 1
int led2 = 12; // pin connected to led 2
int led3 = 11; // pin connected to led 3
int downButton = 7; // button used to decrease value
int upButton = 2; // button used to increase value
int ledValue = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(downButton, INPUT);
pinMode(upButton, INPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if (ledValue = 1){
digitalWrite(led1, HIGH);
} else {
digitalWrite(led1, LOW);
}
}
Welcome to the forum!
Note the difference between "=" and "=="
Thank you. As always my mistake is something stupid and simple. I can never decide if that makes it more or less frustrating.
If the problem is solved, please mark thread
Ok.