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. This code will light the center shamash pixel in red, then light the 8 individual candle pixels sequentially in gold each time the D0 capacitive touch pad is touched.
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.
Head to https://maker.makecode.com and select New Project. Choose the Gemma M0 board. Give your project a name. I called mine Hanukkah Sweater.
On Start Block
First we'll write the code that runs once, when the Gemma powers up. This is where we set up our variables and set up our pixel strip.
Click the LIGHT tab. Another tab titled MORE... will appear. Click on that one to find lots of options for attaching and controlling a NeoPixel strand soldered to the Gemma M0. Drag an instance of
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
Above the LIGHT tab there's another tab called PIXEL. Anything in here controls the onboard NeoPixel on the face of the Gemma M0. I want this turned off on my sweater -- no stray status lights for me, thank you -- so I dragged an instance of
Go to the VARIABLES tab and create a new variable called
From VARIABLES, drag an instance of
Finally, let's make the middle shamash pixel red. From LIGHT > MORE... drag an instance of
Next we'll set up the main body of the code, in our FOREVER loop. Anything in this loop will run over and over, forever.
We can keep this part really simple.
Go back to the LIGHT > MORE... tab and drag an instance of
Now, all we need to do is set up our input. We want each pixel to light up in sequence whenever we touch our capacitive touch pad (D0).
Drag an instance
You may have noticed that over on the left, a little NeoPixel emulator strip has appeared beneath your Gemma M0. This emulator will run whatever your code is doing. This is a really easy way to preview your code and see if it's working without having to download it every time.
Try clicking your D0 pad in the emulator a few times and see what happens.
It's working! Each candle turns sequentially gold when we click the pad.
However, it's not quite perfect. The shamash candle is at pixel 4, and this code overwrites the red color as it counts up. We can fix this by setting the pixel back to red each time the button is clicked.
Add an instance of
Closer! This code sets the pixel to orange but then sets it back to red again. This code accomplishes the goal.
We can go with this code, or we can get fancy and add one more step. We can use logic to get our
day variable to "skip" pixel 4, for a much smoother user experience.
Under the LOGIC tab, find an
Now, if the pixel number is 4, the variable day will change by 2 instead of changing by just 1.
Try this out on the emulator to see what happens.
This works great! We can stop here, or add one more fancy feature: we can code a reset at the end, so if we accidentally go too far (or just want to be able to play with the sweater indefinitely) the code will start over at the beginning.
Select your logic loop and copy/paste it into your workspace to get another instance.
Make it read
Also drag (or copy/paste) another instance of
Try it out on your emulator. Once you're happy with the way it works, click the DOWNLOAD button to program your Gemma.
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.
If it's not working, here are a few things to check:
- Did you set your strip to pin D1 in the on start block? I seem to miss this step sometimes.
- Did you call the onboard pixel instead of the strip? These blocks are similar and easy to confuse. Make sure you're suing
set strip pixel colorand not
set pixel color
- If you just can't make it work, try starting with the completed code linked at the top of the page and working backwards
If your GEMMABOOT drive is not appearing, check out this guide for more troubleshooting tips.