from machine import Pin,ADC
from time import sleep
led = Pin(25, Pin.OUT) # GPIO25 as an output
my_input = Pin(26, Pin.IN, Pin.PULL_UP) # GPIO26 as an input
adc = ADC(Pin(32))
adc.atten(ADC.ATTN_11DB)
adc.width(ADC.WIDTH_12BIT)
while True:
if my_input.value() == 0:
led.on()
input = "the value of the buttom is 1 "
print(input.format(my_input.value),end= "\r")
sleep(1)
else:
led.off()
input = "the value of the buttom is 0"
print(input.format(my_input.value),end= "\r")
sleep(1)
adc_value = adc.read()
volts=(3.3*adc_value)/4095
output=" \t\t\t\t The output voltage is {:0.2f}volts and raw value is {:3d}"
print(output.format(volts,adc_value),end= "\r")