When I press the switch, LED will trun off the light, otherwise, it will turn on.
void setup() {
// confihure the input and the output pins
pinMode(2, OUTPUT); // the LED
pinMode(3, INPUT); // the switch
}
void loop() {
// read the state of the pushbutton
int buttonState = digitalRead(3);
// write to the LED depending on the state of the button
if (buttonState == HIGH) {
// turn the LED on
digitalWrite (2, LOW);
} else {
// turn the LED off
digitalWrite(2, HIGH);
}
}
void setup() {
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(2)==HIGH){
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
}
else{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
}
}