Hello everyone I have been having this problem for a while now. When ever I try to use an if statement it doesn't execute at all. Here is an example of me trying to use a button connected to digital pin 4 to trigger the built-in led.
int inPin = 4;
int val = 0;
void setup()
{
pinMode(inPin, INPUT);
Serial.begin(9600);
digitalWrite(LED_BUILTIN, LOW);
}
void loop()
{
val = digitalRead(inPin); // read the input pin
if (val == 1){digitalWrite(LED_BUILTIN, HIGH); Serial.println("LED active");}
Serial.println(val);
}
When I run it I get an accurate update of the button's state coming through the serial port but it doesn't print "LED active" or turn the led on. Does anyone know what is going on