code.py
 1  # SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  # CircuitPython for the Adafruit Learning System Tutorial
 6  # Universal Marionette Kit
 7  # Project by Dano Wall, code by Anne Barela for Adafruit Industries
 8  # MIT License
 9  import time
10  from adafruit_crickit import crickit
11  
12  # For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing!
13  ss = crickit.seesaw
14  
15  # four buttons with pullups, connect to ground to activate
16  BUTTON_1 = crickit.SIGNAL1  # button #1 connected to signal port 1 & ground
17  BUTTON_2 = crickit.SIGNAL2  # button #2 connected to signal port 2 & ground
18  BUTTON_3 = crickit.SIGNAL3  # button #3 connected to signal port 3 & ground
19  BUTTON_4 = crickit.SIGNAL4  # button #4 connected to signal port 4 & ground
20  
21  ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP)  # Set as input with a pullup resistor
22  ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP)
23  ss.pin_mode(BUTTON_3, ss.INPUT_PULLUP)
24  ss.pin_mode(BUTTON_4, ss.INPUT_PULLUP)
25  
26  while True:
27      if not ss.digital_read(BUTTON_1):
28          print("Button 1 pressed")
29          crickit.servo_1.angle = 40
30          time.sleep(0.1)
31      else:
32          crickit.servo_1.angle = 140
33      if not ss.digital_read(BUTTON_2):
34          print("Button 2 pressed")
35          crickit.servo_2.angle = 140
36          time.sleep(0.1)
37      else:
38          crickit.servo_2.angle = 40
39      if not ss.digital_read(BUTTON_3):
40          print("Button 3 pressed")
41          crickit.servo_3.angle = 40
42          time.sleep(0.1)
43      else:
44          crickit.servo_3.angle = 140
45      if not ss.digital_read(BUTTON_4):
46          print("Button 4 pressed")
47          crickit.servo_4.angle = 140
48          time.sleep(0.1)
49      else:
50          crickit.servo_4.angle = 40