-
Notifications
You must be signed in to change notification settings - Fork 5
/
set_slot.py
65 lines (52 loc) · 2.03 KB
/
set_slot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import time
from machine import Pin
from pimoroni_yukon import Yukon
from pimoroni_yukon import SLOT1 as SLOT
"""
Initialise the IO pins on a Yukon slot as outputs and set them.
Press "Boot/User" to exit the program.
"""
# Constants
SLEEP = 0.5 # The time to sleep between each toggle
# Variables
yukon = Yukon() # A new Yukon object
# Configure the slot pins as outputs with a low state
SLOT.FAST1.init(Pin.OUT, value=False)
SLOT.FAST2.init(Pin.OUT, value=False)
SLOT.FAST3.init(Pin.OUT, value=False)
SLOT.FAST4.init(Pin.OUT, value=False)
SLOT.SLOW1.init(Pin.OUT, value=False)
SLOT.SLOW2.init(Pin.OUT, value=False)
SLOT.SLOW3.init(Pin.OUT, value=False)
# Store the slot pins in a list for easier access
pins = [SLOT.FAST1, SLOT.FAST2, SLOT.FAST3, SLOT.FAST4,
SLOT.SLOW1, SLOT.SLOW2, SLOT.SLOW3]
current_pin = 0
# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
try:
# Loop until the BOOT/USER button is pressed
while not yukon.is_boot_pressed():
# Toggle the current slot pin
pins[current_pin].toggle()
# Advance the current pin, and wrap when the end of the list is reached
current_pin = (current_pin + 1) % len(pins)
# Read the output states of the slot pins
state_f1 = SLOT.FAST1.value()
state_f2 = SLOT.FAST2.value()
state_f3 = SLOT.FAST3.value()
state_f4 = SLOT.FAST4.value()
state_s1 = SLOT.SLOW1.value()
state_s2 = SLOT.SLOW2.value()
state_s3 = SLOT.SLOW3.value()
# Print out the pin states in a nice format
print(f"F1 = {state_f1}", end=", ")
print(f"F2 = {state_f2}", end=", ")
print(f"F3 = {state_f3}", end=", ")
print(f"F4 = {state_f4}", end=", ")
print(f"S1 = {state_s1}", end=", ")
print(f"S2 = {state_s2}", end=", ")
print(f"S3 = {state_s3}")
time.sleep(SLEEP) # Sleep for a number of seconds
finally:
# Put the board back into a safe state, regardless of how the program may have ended
yukon.reset()