The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

144 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


when clicked
forever
if not gpio^2 is high then
set pushed to 1

This block stack watches out for the button being pushed, then sets the variable ‘pushed’
to 1. Setting a variable this way lets you store the fact the button has been pushed, even
though you’re not going to act on it right away.
Go back to your original block stack and find the if then block. Drag a n = n Operator
block into the if then block’s diamond blank, then drag a pushed reporter block into the first
blank square. Type ‘0’ into the second blank square.

when clicked
setgpio^2 to input
forever
if pushed =^0 then
setgpio 25 to output high
wait 5 secs
setgpio^8 to output high
wait^2 secs
setgpio^25 to output low
setgpio^8 to output low
setgpio^7 to output high
wait^5 secs
setgpio^7 to output low
setgpio 8 to output high
wait 5 secs
setgpio^8 to output low
else
Free download pdf