MakeCode is Microsoft's ritzy drag-and-drop code editor. It makes it easy to get up and running with the Gemma M0.
Find the Gemma M0 code editor at maker.makecode.com
Here's my completed project, which runs a pink, blue and purple gradient along the LED strand. Click the Download link at the bottom, plug your Gemma M0 into your computer, click or double-click the reset button and drag the file onto the resulting GEMMABOOT drive.
Or, follow along below to create your own project from scratch.
Code It Yourself
Head to https://maker.makecode.com and select New Project. Choose the Gemma M0 board. Give your project a name. I called mine Spats.
Note: NeoPixels are also called WS2812 pixels, and DotStars are also called APA102 -- make sure you've got the right ones selected.
Next, drag an instance of
strip set brightnessinto your
on start loop. Set the brightness to whatever you'd like. I want them as bright as possible, so I chose
Hue, Saturation and Value
Hue, saturation and value are a means of defining a specific color using just numbers, on a scale of 0-255.
Hue refers to the color on the spectrum -- red, blue, purple, etc. Red is at 0, blue is at around 140, purple comes in at around 180, and the spectrum loops around back to red at 255.
Saturation refers to how pastel or how vivid the colors are: 0 is a plain white, no matter what your hue is -- any completely unsaturated color just turns white. 255 is fully vivid and saturated with color.
Value, for our purposes, refers to the brightness or intensity of the color. The higher the value, the more red or blue is added.
You can read far more than you ever wanted to know about this on Wikipedia. What matters to us is that we can mess with the NeoPixel colors in all sorts of fun ways using hue, saturation and value.
Almost there! We've created a customizable rainbow animation on our strip. However, I don't want a full rainbow -- I just want a partial rainbow, or a gradient animation. We can limit our hue variable to only show hues in one part of the spectrum using an
if / then statement.
We'll start with a hue of 140 (blue), then increase by 2 until we reach 240 (magenta), at which time we will place a limit and tell the code to circle back around to 140.
Now the hue number will count up from 140 (since you set it to 140 in the setup block) by 2's, until it reaches 240, at which point it will pop back down to 140. This effectively makes the NeoPixels change from blue (140) to magenta (240) and then back again. Success! We've got our gradient.
It's easy to change these values to get the color gradient you want.
Plug your Gemma M0 into your computer using a USB cable. Click the tiny Reset button in the middle of the board and the onboard pixel will turn green. When the lights turn green, a new drive will appear on your computer called GEMMABOOT.
In MakeCode, click the Download button to download your code to a file. Drag this file onto the GEMMABOOT drive. It may also ask you if you'd like to pair the board to your computer. Feel free to follow the directions to do this (you may need to update the bootloader), or you can skip it and simply drag the downloaded file onto GEMMABOOT. Pairing the board makes it easier if you want to download and test again and again, since it will load the code automatically without you needing to drag the file each time.