Makecode use of the switches could not be simpler. There are several ways to read the switches and use that action to trigger other actions in code.
First, each button has its own block in the INPUT blok group to do an action if a switch movement is detected:
The on button
blocks are the same, you just select button A
for the left button, button B
for the right button. The on switch
moved block is used twice also, to detect a left
or right
movement of the switch.
For the push buttons you can also read them in a conditional, such as an if..then
block similar to the one below.
Here is a program that lights NeoPixels depending on the switch activations:
- Pushbutton A makes NeoPixel 0 Green
- Pushbutton B makes NeoPixel 9 Green
- Slide switch left makes NeoPixel 4 Blue, right makes NeoPixel 5 Blue
This program can be downloaded below.