/ Crickits / trash_panda / code.py
code.py
 1  # SPDX-FileCopyrightText: 2018 Limor Fried for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  from digitalio import DigitalInOut, Direction
 7  from adafruit_seesaw.seesaw import Seesaw
 8  from adafruit_seesaw.pwmout import PWMOut
 9  from adafruit_motor import servo
10  from busio import I2C
11  import board
12  
13  
14  # Create seesaw object
15  i2c = I2C(board.SCL, board.SDA)
16  seesaw = Seesaw(i2c)
17  
18  led = DigitalInOut(board.D13)
19  led.direction = Direction.OUTPUT
20  
21  # Create servos list
22  servos = []
23  for ss_pin in (17, 16, 15, 14):
24      pwm = PWMOut(seesaw, ss_pin)
25      pwm.frequency = 50
26      _servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500)
27      _servo.angle = 90   # starting angle, middle
28      servos.append(_servo)
29  
30  print("Its TRASH PANDA TIME!")
31  
32  while True:
33      print("tick")
34      led.value = True
35      servos[0].angle = 0
36      time.sleep(0.5)
37      servos[1].angle = 180
38      time.sleep(0.5)
39      servos[2].angle = 0
40      time.sleep(0.5)
41      print("tock")
42      led.value = False
43      servos[0].angle = 180
44      time.sleep(0.5)
45      servos[1].angle = 0
46      time.sleep(0.5)
47      servos[2].angle = 180
48      time.sleep(0.5)