If you haven't used MakeCode before, this guide is a good place to start.
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.
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!
This sketch in MakeCode uses CRICKIT's capacitive touch sensing abilities to trigger the servo motor.
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.
forever block there is an
if statement, which says:
If the value of
crickit read touch 1rises to between
Then play a sound (in this case "
ba ding") and raise the gate for
200msbefore 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.