Another option for your flapping vampire bat is to code it with MakeCode. You can drag and drop the .UF2 code file onto your Circuit Playground Express to quickly prepare your bat to take flight.
Microsoft MakeCode for Adafruit is a web-based code editor that provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.
If you've never used the Circuit Playground Express with MakeCode before, this guide is a good place to start.
Wiring
For this version, the left wing servo data cable is attached to pin A1 and the right wing servo data cable is attached to pin A2.
The Code
To download the code, click the download link at the bottom of the window. To edit the code in MakeCode, click the box with arrow icon in the upper right corner of the window.
You can also download the compiled .UF2 file directly below.
How to Upload Code
To upload code to Circuit Playground Express, follow these instructions:
1) Connect your Circuit Playground Express to your computer using a known, good data+power micro USB cable and press the small reset button in the center of the board. All the LEDs will flash red briefly, then turn green. Your computer should now show a removable drive called CPLAYBOOT.
2) Click the Download button in the code window below to download the .UF2 file to your computer.
3) Now drag and drop the .UF2 file onto the CPLAYBOOT drive in your computer's file explorer or finder.
Once the file is dragged onto CPLAYBOOT, the drive will automatically eject itself (your computer may give you a "failed to eject drive correctly" error, you can ignore this). The code is now on your Circuit Playground Express and ready to run!
Note: If you get a drive named CIRCUITPY, no worries! Press the reset button twice to get a flash drive named CPLAYBOOT. The project will not run if copied onto the CIRCUITPY drive as it is for CircuitPython.
When the code begins, a few variables are defined:
-
right_angle
- the angle of the servo for the right wing -
left_angle
- the angle of the servo for the left wing -
min_range
- the minimum angle for the servos -
max_range
- the maximum angle for the servos -
speed
- the length of the delay -
degree_change
- the amount of movement for the servos
In the loop, the NeoPixels display a rainbow animation while the code is running. Then, the left_angle
and right_angle
values are changed by the degree_change
. If either value leaves the range defined by min_range
and max_range
, then the values are reset. The servo pins set the servo angles to the left_angle
for the left wing and right_angle
for the right wing.
Page last edited March 08, 2024
Text editor powered by tinymce.