Back to Parent

int ledPin = D2;
int switchPin = D3;

void setup() {
    pinMode(ledPin, OUTPUT); // set as an output
    pinMode(switchPin, INPUT_PULLUP); // set as an input
}

void loop() {
    int buttonStatus = digitalRead(switchPin);
    if (buttonStatus == LOW){ // when the switch is turned on
        digitalWrite(ledPin, HIGH); //turn the light on
    }else{
        digitalWrite(ledPin, LOW); // if not, turn the light off
    }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0