/ Party_Parrot_Zoetrope / code.py
code.py
1 # SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries 2 # SPDX-License-Identifier: MIT 3 4 from adafruit_crickit import crickit 5 6 # crickit setup 7 ss = crickit.seesaw 8 # pin for photo interrupter 9 photo = crickit.SIGNAL1 10 ss.pin_mode(photo, ss.INPUT_PULLUP) 11 12 # dc motor setup 13 motor = crickit.dc_motor_1 14 15 # party parrot colors for the NeoPixel 16 parrot_0 = (255, 75, 0) 17 parrot_1 = (255, 200, 0) 18 parrot_2 = (90, 255, 90) 19 parrot_3 = (0, 255, 255) 20 parrot_4 = (0, 160, 255) 21 parrot_5 = (90, 0, 255) 22 parrot_6 = (175, 0, 255) 23 parrot_7 = (255, 0, 200) 24 parrot_8 = (255, 0, 125) 25 parrot_9 = (255, 0, 0) 26 27 colors = (parrot_0, parrot_1, parrot_2, parrot_3, parrot_4, parrot_5, 28 parrot_6, parrot_7, parrot_8, parrot_9) 29 30 # setup using crickit neopixel library 31 crickit.init_neopixel(1) 32 crickit.neopixel.fill((parrot_0)) 33 34 # counter for party parrot colors 35 z = 0 36 # speed for the dc motor 37 speed = 0.3 38 39 while True: 40 # begin the dc motor 41 # will run throughout the loop 42 motor.throttle = speed 43 # read the input from the photo interrupter 44 data = ss.digital_read(photo) 45 46 # if the photo interrupter detects a break: 47 if data is True: 48 # debug print 49 print(z) 50 # change the neopixel's color to the z index of the colors array 51 crickit.neopixel.fill((colors[z])) 52 # increase z by 1 53 z += 1 54 # if z reaches the end of the colors array... 55 if z > 9: 56 # index is reset 57 z = 0