diff --git a/examples/yukon/read_internals.py b/examples/yukon/read_internals.py new file mode 100644 index 0000000..f7e763e --- /dev/null +++ b/examples/yukon/read_internals.py @@ -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() diff --git a/examples/yukon/read_slot.py b/examples/yukon/read_slot.py index 7f4ad7d..dd0a59b 100644 --- a/examples/yukon/read_slot.py +++ b/examples/yukon/read_slot.py @@ -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 diff --git a/examples/yukon/set_slot.py b/examples/yukon/set_slot.py index c81b433..7a97ee0 100644 --- a/examples/yukon/set_slot.py +++ b/examples/yukon/set_slot.py @@ -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