from machine import ADC, Pin # import ADC and Pin classes
import time # import time module
adc = ADC(26) # create ADC object from Pin26
pinLED = Pin(28, Pin.OUT)
try: # if have no error, run the program between try: and except:
while True: # create an infinite loop
adcValue = adc.read_u16() # read ADC value
voltage = adcValue / 65535.0 * 3.3 # calculate voltage
# print ADC value and voltage
print("ADC Value:", adcValue, "Voltage:", voltage, "V")
time.sleep(0.1) # sleep 100 milliseconds
if voltage == 3.3:
pinLED.on() # set pinLED turn on
else:
pinLED.off() # set pinLED turn on
except: # if have error, run the program between except:
pass # do nothing