Circuit Playground Express Basic Input-Output

The real power of microcontrollers is in using them to give outputs to lights, speakers, motors, or pretty much any other electronic device based on inputs given to them from buttons, keyboards, sensors, etc…  In this recipe, we will experiment with basic inputs and outputs on the Circuit Playground Express (CPE) using only its onboard sensors, lights and speakers. Check out the Additional Input/Output Recipes for working with devices outside of the board.

Ingredients

 

Directions

  1. Go to http://makecode.adafruit.com and start a new project.
  2. We are going to assign each button to change the lights to a different color. Begin by dragging the on button A click block out of the “Inputs” group of blocks. Unlike the first recipe, you aren’t putting this inside of the forever loop, just out onto the workplace by itself. Whatever you put inside of it will be triggered whenever the A button on the board is pressed.
  3. From the “Lights” Group, drag out a show ring block and place it inside of the on button A click block. To make things simple, set all of the lights in the ring yellow. If you click the “A” Button on the simulator the lights on the board should all turn yellow.
    Untitled_-_Adafruit_Circuit_Playground_Express.png
  4. We want to do the same thing with button B, but have it switch the color of the lights. An easy way to do this is to duplicate the button A chunk of code and change it so the lights turn another color (blue in our example) when you press button B.
    ezgif.com-video-to-gif.gif
  5. Just for fun, repeat step 4, this time changing the drop-down menu to “Buttons A+B” and setting whichever color you like.
  6. Download your code and send it over to the CPE board. If you forget how you can review from Step 6 in the “Hello World” Recipe.

 

Garnishes

  • Try mixing some of the sounds in with the show ring blocks to change what happens when you press the button.
  • Play with the other “Input” blocks ( on shake, on loud sound, on light, and on switch moved) which work the same way as the on blocks you just used. Can you figure out how they work and make them do things as well?

Leave a comment

Mintz Family iLab Project Blog

Things I've made and helped others make. Stories about creating and messing up.

Kris Swanson dot Blog

Things I've made and helped others make. Stories about creating and messing up.