EasyManua.ls Logo

Sparkfun Electronics Inventor's Kit - Expected Results: Button Press Control

Sparkfun Electronics Inventor's Kit
83 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
On Event
Under the Advanced blocks you can find the Control blocks. These are the blocks that are the most
complicated to use, but are the most powerful. The
OnEvent
block accepts an event type to watch
for and a pin that event should happen on. When that specific event is emitted from that pin, it will
trigger whatever code is inside of it. Take a moment to look through the list of different events that
you can listen for!
if / Else if / Else
Finally, inside of the
forever
block is a more complex
if
block, which is an
if/ifelse/
else
tree. To build this more complex “if” statement, add a standard
if/else
block into your
program. Then click on this small gear in the upper left-hand corner of the block. This will open a tiny
interface with more blocks in it. You can drag more
elseif
blocks into the structure here to build
your decision tree. Here is what ours looks like:
Once you are done rearranging your “if” statement you can close this menu by clicking on the gear
again.
What You Should See
When you press the button, the RGB will turn on to a color. When you press it again, the color will
change and another press will change the color once again. Press it one more time, and it will turn
off. Every time you press the button, it increments a variable, and then we check against it to set the
color. If the variable goes over the value of 2, we reset it to 0, which is off.