from machine import ADC, Pin
import time
# Define the ADC pins for the potentiometers
pot1 = ADC(Pin(26)) # Change to the actual pin number if different
pot2 = ADC(Pin(27)) # Change to the actual pin number if different
pot3 = ADC(Pin(28)) # Change to the actual pin number if different
# Function to read potentiometer values
def read_potentiometers():
# Read the ADC values (0-65535 range)
val1 = pot1.read_u16() / 65535 # Normalize to 0-1 range
val2 = pot2.read_u16() / 65535 # Normalize to 0-1 range
val3 = pot3.read_u16() / 65535 # Normalize to 0-1 range
return val1, val2, val3
# Initialize previous values and timestamps
prev_val1, prev_val2, prev_val3 = read_potentiometers()
stable_val1, stable_val2, stable_val3 = prev_val1, prev_val2, prev_val3
last_change_time = time.time()
debounce_time = 1.0 # Time in seconds to consider the value stable
# Main loop
while True:
# Read current values
val1, val2, val3 = read_potentiometers()
# Check if values have changed
if (val1 != stable_val1) or (val2 != stable_val2) or (val3 != stable_val3):
# Update stable values
stable_val1, stable_val2, stable_val3 = val1, val2, val3
last_change_time = time.time()
# Print the new values and status
#print(f"Potentiometer values changed to: pot1={stable_val1:.4f}, pot2={stable_val2:.4f}, pot3={stable_val3:.4f}")
# Check conditions
if stable_val1 > 2/65535 and stable_val2 < 1/65535 and stable_val3 < 1/65535:
print("Workout is correct")
else:
print("Workout angle is incorrect")
# Wait for a while before checking again
time.sleep(0.1) # Adjust the delay as needed