# import all the modules needed
from machine import Pin,ADC
from time import sleep
#configure the Led output pins
led_27 = Pin(27,Pin.OUT)
led_26 = Pin(26,Pin.OUT)
led_25 = Pin(25,Pin.OUT)
led_33 = Pin(33,Pin.OUT)
led_32 = Pin(32,Pin.OUT)
#configure the ADC
adc = ADC(Pin(2))
adc.atten(ADC.ATTN_11DB) #sets the maximum voltage og 3.6 volts
adc.width(ADC.WIDTH_9BIT) #sets the width to 9bits
#define the functiojns used
def binarycount(x):
binary = '{0:05b}'.format (x)
led_27.value(int(binary[0]))
led_26.value(int(binary[1]))
led_25.value(int(binary[2]))
led_33.value(int(binary[3]))
led_32.value(int(binary[4]))
def map(x,in_min,in_max,out_min,out_max):
return int((x-in_min)*(out_max-out_min)/(in_max-in_min)+out_min)
def main():
while True:
adc_value = adc.read()
volts = (3.3*adc_value)/511
input_voltage = "Th eiput voltage is {:0.2f} volts and the raw value is {:4d}"
print(input_voltage.format(volts,adc_value),end = "\r")
binarycount(map(adc_value,0,512,0,32))
main()