Back to Parent

int ledPin = D2;
int buttonPin = D3;

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

void loop() {
    int buttonStatus = digitalRead(buttonPin);
    if (buttonStatus == LOW){ // when the button is pressed
        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