from machine import ADC, Pin
import time
# Define ADC pins for the potentiometers
pot1 = ADC(Pin(26)) # Potentiometer 1 connected to pin 26
pot2 = ADC(Pin(27)) # Potentiometer 2 connected to pin 27
pot3 = ADC(Pin(28)) # Potentiometer 3 connected to pin 28
# Function to read and normalize potentiometer values
def read_potentiometers():
# Read ADC values and normalize them to the range 0-1
val1 = pot1.read_u16() / 65535 # Potentiometer 1 value normalized
val2 = pot2.read_u16() / 65535 # Potentiometer 2 value normalized
val3 = pot3.read_u16() / 65535 # Potentiometer 3 value normalized
return val1, val2, val3
# Initialize timing for printing status
last_print_time = time.time() # Record the time of the last print
print_interval = 5.0 # Interval to print status updates (10 seconds)
# Main loop
while True:
# Read current potentiometer values
val1, val2, val3 = read_potentiometers()
# Get the current time
current_time = time.time()
# Check if the time since the last print is greater than or equal to the print interval
if (current_time - last_print_time) >= print_interval:
# Determine the status of each muscle based on the potentiometer values
muscle1_status = "Activated" if val1 > 2 / 65535 else "Relaxed"
muscle2_status = "Activated" if val2 > 1 / 65535 else "Relaxed"
muscle3_status = "Activated" if val3 > 1 / 65535 else "Relaxed"
# Print the statuses of the muscles
print(f"Muscle 1: {muscle1_status}")
print(f"Muscle 2: {muscle2_status}")
print(f"Muscle 3: {muscle3_status}")
# Determine if the workout is correct based on muscle statuses
if muscle1_status == "Activated" and muscle2_status == "Relaxed" and muscle3_status == "Relaxed":
print("Workout is correct")
else:
print("Workout angle is incorrect")
# Update the time of the last print
last_print_time = current_time
# Sleep for a short time before checking again to avoid too frequent reads
time.sleep(0.1) # Delay to allow for periodic reading without overwhelming the system