What is Circuit Playground Express (CPX)?

The Circuit Playground Express is an easy way to get started learning electronics and coding. It's filled with tons of fun lights and sensors! The CPX is what we'll use to control the mouse and keyboard to draw in our new Scratch program. Head here to learn more about the CPX.

What is MakeCode?

MakeCode is a web-based code editor for physical computing made by Microsoft.

It is almost identical to Scratch in design, however it is mainly for programming hardware like the CPX rather than a sprite on a computer screen.

More on MakeCode for Adafruit boards here.

Create a New Project with MakeCode

Head over to https://makecode.adafruit.com/ and create a new project.

Click the button below to access the code for this project.

Add the Keyboard and Mouse Extensions in MakeCode

Follow this guide on how to add these extensions to MakeCode. They will allow us to use the CPX to act as a mouse and a keyboard!

The NeoPixel Palette

  • In an on start loop, set the colors of the NeoPixels on the CPX to the according colors. This is so the user knows which colors they have to choose from.

Coding with the accelerometer

1 G (one gee) is equivalent to Earth's gravitational pull at a resting point.

The CPX's accelerometer senses the gravity it feels in any given direction on the x, y or z axis. The value it senses is anywhere from 0 to 1023 mg (miligravities). 1G = 1000 miligravities.

Learn more about the accelerometer on the Circuit Playground Express here.

  • In a forever loop, we create an if else statement that describes how the mouse should move when the CPX is tilted forwards, to the right, backwards, or to the left. 


  • If the accelerometer senses any more that 500mg in any direction, the mouse will move in that direction.

Sending keyboard info

  • When button A is clicked, the CPX sends the character c for color change.


  • When the CPX is shaken, the CPX sends the character e for erase.

Uploading the Code

Now that we have the code for the project, we need to upload it to the CPX.

Let's name our file and download it.

  • Choose a name at the bottom of the page.
  • Then click the pink Download button.

Follow the directions and connect your CPX to your computer via the USB cable. Click the CPX Reset button once to go into programming mode (all the Circuit Playground Expresses' LED light NeoPixels will turn green).

In some cases, you may need to press the reset button twice to get into programming mode.

Next, look for the file in your downloads folder and drag it onto your CPLAYBOOT drive that should have showed up in your file manager/finder when you plugged in your board and entered programming mode.

Once your code file is placed on the CPLAYBOOT drive should  see the CPLAYBOOT drive disappear indicating the code is running.

This guide was first published on Jan 18, 2019. It was last updated on Jan 18, 2019.

This page (CPX and MakeCode) was last updated on Jan 16, 2019.

Text editor powered by tinymce.