I am trying a simple sketch to turn on an LED when pressed (following a Youtube video tutorial.) I used an "if" condition statement to read the button and turn on an LED and also print some text on the Serial monitor.
When i upload the code, the Serial monitor prints the text even without pressing the button vut the LED works as supposedly.
I have both the SM and LED code in the "if" statement but only the LED follows the instruction.
int buttonpin = 6; //push button
int ledyellow = 7; //yellow LED
float delset = 0; //delay set time
int pinread;
void setup() {
Serial.begin(9600);
pinMode(buttonpin, INPUT_PULLUP);
pinMode(ledyellow, OUTPUT);
}
void loop() {
pinread = digitalRead(buttonpin);
if (pinread == LOW) {
//delset = delset + 5;
Serial.print("ms > ");
Serial.println(delset);
digitalWrite(ledyellow, HIGH);
}
else {
digitalWrite(ledyellow, LOW);
}
}