Coding your first neopixel on MakeCode
There is no need to have a neopixel for this activity. We will use the emulator and the neopixel extension in MakeCode to visualize the result of our code.
Open MakeCode and follow along or read the goals of this activity and try to do it as a challenge.
Goals
Have the micro:bit set up a strip of neopixels with the following conditions:
Part A
The neopixel is controlled by the pin zero (0) on the micro:bit.
The neopixel LED strip has 10 LEDs.
The colour format used is RGB.
Part B
Show the strip on the emulator. This one is trickier than it seems. Make sure to read the tip from the clear block.
When the user presses the A button, set the colours of all of the LEDs to red.
When the user presses the B button, set the colours of the LEDs to colours from the rainbow.
When the user presses buttons A and B at the same time, the neopixel will turn off (clear). This challenge is a bit trickier than it seems. It requires you to read the tooltip on the clear block.
When the user shakes the micro:bit, the pixel colours rotate within the neopixel. This process requires reading the tooltip on the rotate pixels block.
Once you have tried solving the challenges, compare your solution with our below.
Our solution
Add the neopixel Extension to your MakeCode project
To start, we need to enable the Servo extension in MakeCode. To do so, click on Extensions.

Add the servo extension from the list
Now you have access to a new group of blocks and the emulator includes a virtual neopixel strip They provide different ways of setting up and controlling the lights.
Setup the neopixel
Part A is all contained in one block. This block creates a variable named strip and determines the pin it will be receiving information from the micro:bit, the number of LEDs we are using in the neopixel and what colour mode we are using.
Part B is a very important step and one that is easy to overlook. Every time we make a change to the neopixel, it is required that we update the current status by adding the show block.
![]()
Test on the emulator and see the emulator show 10 unlit LEDs.
Press Button A, B and A+B to change colours
All these three actions follow the same pattern. We introduce a block that will trigger action and depending on the button pressed, then pick the desired colour.
Button A to set all LEDs to be red
![]()
Button B to set all LEDs to colours of the rainbow
We are using numbers that go from 0 to 360. These numbers represent degrees on a colour wheel.
Buttons A+B to turn off all the LEDs on the neopixel
Test on the emulator and see how the colours change when you press the different buttons.
Shake to rotate the colours
Follow the same process as we did for the buttons while changing the event triggering the change, in this case, the shake event. Remember to include the show block at the end.
![]()
Test the results on the emulator!
Next, we dive into data activities.
Last updated
Was this helpful?