Code: Select all
import time
from adafruit_crickit import crickit
# For signal control, we'll chat directly with seesaw, use 'ss' to shorted typing!
ss = crickit.seesaw
# Two buttons are pullups, connect to ground to activate
BUTTON_1 = crickit.SIGNAL1 # button #1 connected to signal port 1 & ground
BUTTON_2 = crickit.SIGNAL2 # button #2 connected to signal port 2 & ground
ss.pin_mode(BUTTON_1, ss.INPUT_PULLUP)
ss.pin_mode(BUTTON_2, ss.INPUT_PULLUP)
# make two variables for the motors to make code shorter to type
motor_1 = crickit.dc_motor_1
motor_2 = crickit.dc_motor_2
while True:
motor_1.throttle = 0.4
motor_2.throttle = 0.4
if not ss.digital_read(BUTTON_1):
print("Button 1 pressed")
motor_1.throttle = -1
motor_2.throttle = -0.5
time.sleep(0.3)
if not ss.digital_read(BUTTON_2):
print("Button 2 pressed")
motor_1.throttle = -0.5
motor_2.throttle = -1
time.sleep(0.3)
Code: Select all
code.py output:
Traceback (most recent call last):
File "code.py", line 2, in <module>
File "adafruit_crickit.py", line 402, in <module>
RuntimeError: No pull up found on SDA or SCL; check your wiring