If you feel more comfortable coding with CircuitPython rather than MakeCode, this page is for you.
The benefits of using CircuitPython for capacitive touch in this case are that it's less likely to freeze (requiring restart), allows greater complexity in any reward scheme you'd like to set up, and allows you to play any sound you want in combination with a treat being dispensed.
Getting Familiar
CircuitPython is a programming language based on Python, one of the fastest growing programming languages in the world. It is specifically designed to simplify experimenting and learning to code on low-cost microcontroller boards.
CircuitPython is easiest to use within the Mu Editor. If you haven't previously used Mu, this guide will get you started.
If you haven't used Circuit Playground Express with CRICKIT before, make sure you've updated it with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.
# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import audioio import audiocore from adafruit_crickit import crickit print("Cat Feeder") feed_servo = crickit.servo_1 # audio output cpx_audio = audioio.AudioOut(board.A0) f = open("activate.wav", "rb") wav = audiocore.WaveFile(f) while True: if crickit.touch_1.value: time.sleep(0.1) cpx_audio.play(wav) feed_servo.angle = 180 time.sleep(0.2) feed_servo.angle = 0 time.sleep(0.1)
Uploading
Make sure you've connected the Circuit Playground Express to your computer and have Mu open and connected to your board.
Once the code is copied into Mu, press the Save button - your code should be saved to the CIRCUITPY disk drive (which appears when the Circuit Playground Express is plugged into your computer) as code.py
.
You may also include a WAV file to play when capacitive touch is triggered. Name this file "activate.wav" in your CIRCUITPY drive for it to be recognized by the code.
If you want to create and use your own wav files, see this guide to ensure they are formatted for playing on CRICKIT.
Troubleshooting
Problem: My Circuit Playground Express isn't recognized by Mu!
Solution: Make sure your board is set up with CircuitPython, which has the Circuit Playground Express show up as a flash drive named CIRCUITPY when you connect the CPX to your computer. If it is showing up as CPLAYBOOT on your computer, you can follow the steps in this guide to ensure CircuitPython is loaded and you see the CIRCUITPY drive.
Problem: My servo isn't moving!
Solution: Check that the switch on CRICKIT is set to "ON".
Problem: My servo still isn't moving!
Solution: Make sure you've updated your Circuit Playground Express with the latest special 'seesaw' version of the CPX firmware. This guide will show you how.
Text editor powered by tinymce.