📊 micro:bit Data and Climate Change
  • Introduction
  • Data
  • Climate Change
  • Our Tools
    • 01- micro:bit
    • 02 - MakeCode
      • A - Events
      • B - Animations
      • C - Counting
      • D - If Hot
    • 03 - Servo Motor
      • Coding your first servo motor on MakeCode
    • 04 - Neopixel
      • Coding your first neopixel on MakeCode
  • Activities
    • Tools and Data Together
      • 01 - micro:bit and Data
      • 02 - Servo Motor and Data
      • 03 - Neopixel and Data
  • Showcase Projects
    • 01 - Air Pollution
      • A - Servo Motor
      • B - Neopixel Grid
    • 02 - Green Energy Forecast
    • 03 - Temperature Change
      • A - Neopixel Grid
      • B - Neopixel Ring
    • 04 - Heavy Precipitation Days
      • A - Neopixel Grid
      • B -Servo Motor
      • C-Neopixel Fairy Lights
    • 05 - Greenhouse Gas Emission
      • A - Neopixel Grid
      • B - Neopixel Fairy Lights
  • 🚀Extra Missions
  • Support Material
    • Data on the Run
    • Data Visualization Examples
    • Data Science of Climate Change by Lucie Luneau
    • Ideas from the Canadian Space Agency - CSA
    • CASC + Science Spotlight
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Our Tools
  2. 04 - Neopixel

Coding your first neopixel on MakeCode

Previous04 - NeopixelNextActivities

Last updated 2 years ago

Was this helpful?

Photo by on

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 and follow along or read the goals of this activity and try to do it as a challenge.

Goals

  1. Have the micro:bit set up a strip of neopixels with the following conditions:

    • Part A

      1. The neopixel is controlled by the pin zero (0) on the micro:bit.

      2. The neopixel LED strip has 10 LEDs.

      3. 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.

  2. When the user presses the A button, set the colours of all of the LEDs to red.

  3. When the user presses the B button, set the colours of the LEDs to colours from the rainbow.

  4. 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.

  5. 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

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.

We are using numbers that go from 0 to 360. These numbers represent degrees on a .

colour wheel
MakeCode
Kilimanjaro STUDIOz
Unsplash