-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7785bda
commit bd2e3b3
Showing
3 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import time | ||
from machine import Pin | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon import SLOT1 as SLOT | ||
|
||
""" | ||
Read the IO pins of a single Yukon slot. | ||
""" | ||
|
||
# Constants | ||
SLEEP = 0.5 # The time to sleep between each reading | ||
|
||
# Variables | ||
yukon = Yukon() # A new Yukon object | ||
|
||
# Configure the slot pins as inputs | ||
SLOT.FAST1.init(Pin.IN) | ||
SLOT.FAST2.init(Pin.IN) | ||
SLOT.FAST3.init(Pin.IN) | ||
SLOT.FAST4.init(Pin.IN) | ||
SLOT.SLOW1.init(Pin.IN) | ||
SLOT.SLOW1.init(Pin.IN) | ||
SLOT.SLOW1.init(Pin.IN) | ||
|
||
# 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(): | ||
|
||
# Read the slot's four 'Fast' pins | ||
state_f1 = SLOT.FAST1.value() | ||
state_f2 = SLOT.FAST2.value() | ||
state_f3 = SLOT.FAST3.value() | ||
state_f4 = SLOT.FAST4.value() | ||
|
||
# Read the slot's three 'Slow' pins. These have internal | ||
# pull-ups so will read 1 if left disconnected | ||
state_s1 = SLOT.SLOW1.value() | ||
state_s2 = SLOT.SLOW2.value() | ||
state_s3 = SLOT.SLOW3.value() | ||
|
||
# Read the slot's two analog pins | ||
adc1 = yukon.read_slot_adc1(SLOT) | ||
adc2 = yukon.read_slot_adc2(SLOT) | ||
|
||
# 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}", end=", ") | ||
print(f"A1 = {adc1}", end=", ") | ||
print(f"A2 = {adc2}") | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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. | ||
""" | ||
|
||
# Constants | ||
SLEEP = 0.5 # The time to sleep between each reading | ||
|
||
# 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() |