Button Control

This lab is the same set-up as the Arduino Button Control Lab but uses mBlock code to achieve the same results.

Code Summary:

The following instructions will teach you to build this:

For instructions on setting up mBlock and uploading the program, be sure to read this link : Install and Upload

Step 1

Go to the Robots category and pull out Arduino Program

Step 2

Go to the Control category and pull out a "forever" loop.  Put the "if then else" scrip inside of it.

Step 3

Go to the Operators category and pull out the = and put it into the "if-then".

Step 4

Go to the Robots script and pull out "read digital pin 9".  Put it into the left box of the = script and change the 9 to a 2.  

Enter the word HIGH in the right box of the = operator.  It must be all in capital letters.

Step 5

In the Robots category, pull out "set digital pin 9 output as HIGH" underneath the if-then.

Pull out another one and put it into the else section.  Change HIGH to LOW in this one.

You are done!  Upload the program and you can now press the button to turn the LED on.


Code Comparison

Note how the if statement translates into Arduino code.  This is almost identical to the Arduino code for the Button Control Arudino lab.