code.py
1 # SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 # CircuitPython 3.0 CRICKIT demo 6 import time 7 8 import board 9 from adafruit_motor import servo, motor 10 from adafruit_seesaw.pwmout import PWMOut 11 from adafruit_seesaw.seesaw import Seesaw 12 from busio import I2C 13 14 i2c = I2C(board.SCL, board.SDA) 15 ss = Seesaw(i2c) 16 17 print("Bubble machine!") 18 19 SERVOS = True 20 DCMOTORS = True 21 22 # Create 4 Servos 23 servos = [] 24 if SERVOS: 25 for ss_pin in (17, 16, 15, 14): 26 pwm = PWMOut(ss, ss_pin) 27 pwm.frequency = 50 28 _servo = servo.Servo(pwm) 29 _servo.angle = 90 # starting angle, middle 30 servos.append(_servo) 31 32 # Create 2 DC motors 33 motors = [] 34 if DCMOTORS: 35 for ss_pin in ((18, 19), (22, 23)): 36 pwm0 = PWMOut(ss, ss_pin[0]) 37 pwm1 = PWMOut(ss, ss_pin[1]) 38 _motor = motor.DCMotor(pwm0, pwm1) 39 motors.append(_motor) 40 41 while True: 42 print("servo down") 43 servos[0].angle = 180 44 time.sleep(1) 45 print("fan on") 46 motors[0].throttle = 1 47 time.sleep(3) 48 print("fan off") 49 time.sleep(1) 50 motors[0].throttle = 0 51 print("servo up") 52 servos[0].angle = 0 53 time.sleep(1)