Skip to content

Commit

Permalink
Example for reading Yukon internals
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Oct 10, 2023
1 parent bd2e3b3 commit 2c1b378
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions examples/yukon/read_internals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import time
from pimoroni_yukon import Yukon

"""
read the internal sensors of Yukon.
"""

# Constants
SLEEP = 0.5 # The time to sleep between each reading

# Variables
yukon = Yukon() # A new Yukon object

# 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 Yukon's voltage sensors
voltage_in = yukon.read_input_voltage()
voltage_out = yukon.read_output_voltage()

# Read Yukon's current sensor, but only if the input voltage
# is high enough to turn it on, otherwise set the value to zero
current = yukon.read_current() if voltage_in > 2.5 else 0.0

# Read Yukon's temperature sensor
temperature = yukon.read_temperature()

# Print out the pin states in a nice format
print(f"Vin = {voltage_in} V", end=", ")
print(f"Vout = {voltage_out} V", end=", ")
print(f"Cur = {current} A", end=", ")
print(f"Temp = {temperature} °C")

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()
2 changes: 1 addition & 1 deletion examples/yukon/read_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

# Constants
SLEEP = 0.5 # The time to sleep between each reading
SLEEP = 0.5 # The time to sleep between each reading

# Variables
yukon = Yukon() # A new Yukon object
Expand Down
2 changes: 1 addition & 1 deletion examples/yukon/set_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

# Constants
SLEEP = 0.5 # The time to sleep between each reading
SLEEP = 0.5 # The time to sleep between each reading

# Variables
yukon = Yukon() # A new Yukon object
Expand Down

0 comments on commit 2c1b378

Please sign in to comment.