My Interface Code

"""This personalised breakfast cereal dispenser system for my children 
that will lights up half the NeoPixels red, play a tone, and open the "door" for 4 seconds while button A is being pressed,
and the other half the NeoPixels blue, play a different tone and open the "door" for 2 seconds while button B is being pressed."""
import time
import board
import pwmio
from adafruit_motor import servo
from adafruit_circuitplayground import cp
from adafruit_circuitplayground.express import cpx

# Create the PWMOut object on CPX Pin A1 for George and A2 for Zoe
pwm1 = pwmio.PWMOut(board.A1, duty_cycle=2 ** 15, frequency=50)
pwm2 = pwmio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)

# Create the servo object using my_servo
my_servo1 = servo.Servo(pwm1)  # For George
my_servo2 = servo.Servo(pwm2)  # For Zoe

# Set the brightness of the pixels to a floating point number between 0 and 1.0
cp.pixels.brightness = 0.5  # I want the brightness to be 0.5

# For playing tones
scale1 = [587, 659, 740, 880, 987, 1174]  # For George
scale2 = [1174, 987, 880, 740, 659, 587]  # For Zoe

while True:
    if cp.button_a:
        # cp.pixels from 0 to 5 all 5
        cp.pixels[0:5] = [(255, 0, 0)] * 5
        # Set up the sound effects using different frequency of tones
        # Modified from the cpx play 2 tones example in Week 7 tutorial and my creature homework
        for note in scale1:
            cpx.play_tone(note, 0.25)

        # for set up servo control tutorial from https://learn.adafruit.com/using-servos-with-circuitpython/high-level-servo-control
        for angle in range(0, 180, 180):  # 0 - 180 degrees, 180 degrees at a time.
            my_servo1.angle = angle
            time.sleep(4) # 4 seconds pour for George
        for angle in range(180, 0, -180):  # 180 - 0 degrees, 180 degrees at a time.
            my_servo1.angle = angle
            time.sleep(1)
    else:
        cp.pixels[0:5] = [(128, 128, 0)] * 5 # yellow colour

    if cp.button_b:
        cp.pixels[5:10] = [(0, 0, 255)] * 5
        for note in scale2:
            cpx.play_tone(note, 0.25)

        # for set up servo control tutorial from https://learn.adafruit.com/using-servos-with-circuitpython/high-level-servo-control
        for angle in range(0, 180, 180):  # 0 - 180 degrees, 180 degrees at a time.
            my_servo2.angle = angle
            time.sleep(2) # 2 seconds pour for Zoe
        for angle in range(180, 0, -180):  # 180 - 0 degrees, 180 degrees at a time.
            my_servo2.angle = angle
            time.sleep(1)
    else:
        cp.pixels[5:10] = [(0, 255, 255)] * 5 # cyan colour

These are the Adafruit tutorials that inspired my cereal dispenser system, I combined and modified the codes that work with Circuit Python in Mu Editor code. These tutorials are reproducible and can be modified accordingly to suit your project. I modified this code based on the codes listed on the links below:

  1. Buttons: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/buttons
  2. Neopixels: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/neopixels
  3. Play Tone: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/play-tone
  4. Using Servos With CircuitPython: https://learn.adafruit.com/circuitpython-essentials/circuitpython-servo
  5. Automatic Cat Treat Dispenser https://learn.adafruit.com/automatic-cat-treat-dispenser/overview