Back to Parent

//Practice exercise: Using a pushbotton

int ledPin = D2;

int buttonPin = D3;


void setup() {

    pinMode(ledPin,OUTPUT); //set pin as output
    
    pinMode(buttonPin, INPUT_PULLUP); //set pin as imput

}

void loop() {

    int buttonState = digitalRead(buttonPin);
    
    if(buttonState == LOW)
    {
        digitalWrite(ledPin,HIGH); //turn the led on
        
    }else{
        digitalWrite(ledPin,LOW); //otherwise turn the led off
    }
}
Click to Expand

Content Rating

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

0