Note:
The full sized breadboard power rails have a break down the middle. If you end up using the
lower half of the power rail you will need to jump between the upper end and lower end.
Run Your Script
Either copy and paste, or re-create the following code into your own MakeCode editor by clicking the
open icon in the upper right-hand corner of the editor window. You can also just download this
example by clicking the download button in the lower right-hand corner of the code window.
Note:
You may need to disable your ad/pop-up blocker to interact with the MakeCode programming
environment and simulated circuit!
Code to Note
Let’s take a look at the code blocks in this experiment.
If you are having a hard time viewing this code, click on the image above to get a better look!
Digital Read
Just as the
digital
write
block turns a pin on (1) or off (0) the
digital
read
block looks at the state
of a pin, which is either HIGH (1) or LOW (0). By building a circuit that connects 3.3V or ground to a
pin, we can detect if a switch is thrown or a button pressed.
The
digital
read
block returns a value so it is shaped to be inserted into a value slot and not a
command. We use an equivalency block from the logic blocks to check if the pin is equal to 1 or 0
and then make a decision from there.