Back to Parent

//Practice exercise: Using a switch

int ledPin = D2;

int switchPin = D3;

void setup() {

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


void loop() {

    int switchState = digitalRead(switchPin);
    if(switchState == LOW)
        digitalWrite(ledPin,HIGH); //turn the led on
        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!