MakeCode
If you're new to MakeCode, check out this guide first.
MakeCode for Circuit Playground Express
In a WebUSB capable browser, such as Chrome, launch the MakeCode Circuit Playground Express editor by clicking this link.
Add Crickit Extension
Click the Advanced button, and then click on Extensions.
This will open the Extensions page, click on the Crickit extension at the bottom to add it to your Makecode editor.
Setup
You'll start with NeoPixel LED setup and by creating variables. These go in the on Start loop block.
The NeoPixel blocks come from the Light category.
Create the variables in the Variable category. To make time easier to track, you'll make a second
variable equal to 1000 milliseconds, and then a minute
variable equal to second
* 60
using the multiplication block in the Math category.
You can then create a turn_time
variable to around 14 seconds (enough for two turns of the watch) using a multiplication block, and the pause_time
of around 4 minutes.
You can adjust these numbers depending on how many turns per day (TPD) you want for you watch. The above settings yield 720 TPD.
Direction Switch
You can use the slide switch on the Circuit Playground Express to determine the direction the winder turns.
From the Input category, grab one each of the on switch moved left/right blocks.
Use the dropdown menu to pick left for one and right for the other. In the left block add a crickit set motor 1 inverted OFF block. This will cause the motor to turn the watch counter-clockwise.
For the right block, set this to ON to turn clockwise.
You will also use set pixel color blocks from the Light category as shown to change the two bottom NeoPixels to indicate direction visually.
Start/Stop Button
Use an on Button A click block from the Input category to start and stop the winder.
A set run to not run block from the Variables category toggles the value of the run
variable.
Then, an if run then...else block from the Logic category set the pixel 0 color to green or red depending on the state, and uses crickit stop motor 1 to stop the motor from turning.
windWatch Function
In the Advanced section, from the Functions category, create a new function called windWatch
.
This is what will be called any time the run
variable is True
in the main Forever loop.
The function will set pixel color at 9 to cyan to indicate the motor is running, then set the cricket run motor 1 to 100
%.
Next, it will pause for the turn_time
.
Then, pixel color at 9 is set to orange to indicate the motor is paused.
crickit stop motor 1 stops the motor from turning, and then pause pause_time
will keep the motor paused until it is time to start the function loop all over again, so long as run
is True
.
forever Loop
Get a forever loop from the Loops category. in it an if run then block from the Logic category is used to call the windWatch function. If the button A is pressed to toggle to off, then run
is False
and this function won't be called. Press button A again to make run
True
and the function will be called.
Download and Flash
In order to put the code on your Circuit Playground Express follow the steps on this page.
Text editor powered by tinymce.