Now it's time to upload some code! For this we will be using Microsoft MakeCode for Adafruit, a web-based code editor. It provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.
If you haven't used MakeCode before, this guide is a good place to start.
Getting into Bootloader Mode
To make your board work with MakeCode we need to put it into "bootloader mode". All that's required to do this is to connect the board to your computer with a micro USB cable and click the small reset button in the center of the board.
Now we're ready for MakeCode!
Click this link or the button below to enter the portal to interact with the code for this project.
How to upload code
To upload code, connect you Circuit Playground Express to your computer using the micro USB cable, click the Download button to download the .uf2 file to your computer, and drag 'n drop it onto the CPLAYBOOT drive.
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!
What does this code do?
This sketch in MakeCode uses CRICKIT's capacitive touch sensing abilities to trigger the servo motor.
In the on start
block we can see that there are two startup commands to set the volume level (not too loud) and lower the servo to ensure the gate starts in the closed position.
In the forever
block there is an if
statement, which says:
-
If the value of
crickit read touch 1
rises to between700
and1000
-
Then play a sound (in this case "
ba ding
") and raise the gate for200ms
before lowering it back down
If you'd like to play with this code, click "Edit" and a new window will open in which you can create your own version.
Before creating your final assembly it's a good idea to test that your circuit works.
Capacitive touch is read as a value between 0 and 1023. You can increase or decrease the capacitive touch 'window' as necessary to get the sensitivity level you need (for example from between >700 and <1000
to between >850 and <950
).
If CRICKIT stops responding to touch altogether a single press of the little reset button will restart the whole thing and bring it back to life again.
Once you're satisfied that your box is working, place CRICKIT and battery pack inside and hold in place with double sided foam tape.
The touch pad can be attached anywhere on the outside of the box where your cat is likely to paw at it (the bottom of the chute is a good place to start). Attach using double sided tape.
Text editor powered by tinymce.