You're ready to program your dreidel with Microsoft MakeCode! If you're new to using MakeCode with the CPX, you can download the sample program below to get started. Look it over as you read through the description below to see how it was put together.
Then, when you get the hang of it, you can personalize the code to make a unique Mystery Dreidel.
To find out more, check out the Adafruit MakeCode Guide.
It may look like there's a lot of stuff on the screen, but don't let it scare you. There are only a few different things happening:
- A stack of code runs as soon as you start the CPX up that sets the volume and the brightness of the lights, runs a light animation, and plays the Dreidel Song (the part that goes "Dreidel, dreidel, dreidel/I made it out of clay/And when it's dry and ready/Then dreidel I will play").
- For each of the four directions the CPX can tilt -- up, down, left, or right -- there is a stack of code that tells the lights on that side to flash in a different color, and play a different pre-made sound.
- A separate stack of code lets you play the Dreidel Song and a different light animation by turning the dreidel upside down (so the CPX is face down).
- Two pieces of code let you turn the sound off (so just the light animations run) when the slide switch on the CPX is pushed to the left and turn it back on by pushing the switch to the right.
Here's a little more detail and a few helpful tips:
Adjust the Settings
To adjust the default settings on the CPX, grab a
Since the CPX is hidden inside the dreidel, you'll probably want to raise them both.
Create Your Own Light Animations
Designing your own lighting effects is easy. Just grab a
For the dreidel program, to flash the lights closest to the side facing up, turn on only the lights on that half of the CPX.
With so much going on, it's hard to see which stack of code goes with each section of the dreidel. Keep track by sticking a comment on your code.
Just right click on any stack of code and click "Add Comment" on the list that pulls down. Then type your notes in the pop-up box so you know what's what.
Write Strings of Musical Notes
You may have created your own short tunes by stacking up a few
To create a string of notes, start with a regular
play sound [ ] until done block from the MUSIC menu. You will replace the oval that has the pull-down menu of pre-made melodies with a blank oval you can type in.
To do that, first you need to click on the Advanced label and several additional categories of menus will appear. Then click on TEXT and grab an empty text oval. Drag it over the existing oval in the
play sound [ ] until done block and it should click in.
Then type in your notes. They are written in the format [name of note] : [number of beats]. The notes are in the Middle Octave unless you add "Low" or "High" in between. So a half-note in Middle C (two beats) is written C:2. And a High D whole note (four beats) is D:High:4.
Play Lights and Music at the Same Time
When you spin the dreidel and it lands on one side, you want the dreidel to light up and play music at the same time. If you just stack up the light and music blocks, the CPX will do one before it starts the next.
To tell the CPX to do both simultaneously, you can use a
In these examples, I've put the light blocks inside the "mouth" of the