# MicroPython Code - Throttle Status Indicator
from machine import Pin, ADC
import time

# Configure ADC on Pin 2 with 11dB attenuation (0 - 3.6V range)
throttle_pin = ADC(Pin(2))
throttle_pin.atten(ADC.ATTN_11DB)

# Configure output LED on Pin 3
led_pin = Pin(3, Pin.OUT)
THRESHOLD = 52428 # 80% of 16-bit range (65535 * 0.8)

while True:
    raw_val = throttle_pin.read_u16() # Reads a 16-bit value (0-65535)
    percentage = (raw_val / 65535.0) * 100
    
    print("Throttle Input: {:.1f}%".format(percentage))
    
    if raw_val > THRESHOLD:
        led_pin.value(1) # Turn LED On
    else:
        led_pin.value(0) # Turn LED Off
        
    time.sleep(0.1)
