0% found this document useful (0 votes)
12 views

Programming Arduino (1) Pages 123

Uploaded by

axl1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Programming Arduino (1) Pages 123

Uploaded by

axl1994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

pinMode(inputPin, INPUT_PULLUP);

void loop()

int switchOpen = digitalRead(inputPin);

digitalWrite(ledPin, ! switchOpen);

Looking at the loop function of sketch 6-04, the function reads the digital
input and assigns its value to a variable switchOpen . This is a 0 if the button is
pressed and a 1 if it isn’t (remember that the pin is pulled up to 1 when the
button is not pressed).
When you program digitalWrite to turn the LED on or off, you need to
reverse this value. You do this using the ! or not operator.
If you upload this sketch and connect your wire between D5 and GND (see
Figure 6-9 ), you should see the LED light. Bouncing may be going on here, but
it is probably too fast for you to see and does not matter.

You might also like