from machine import Pin,ADC,PWM

pwm_21=PWM(Pin(21))
pwm_21.freq(50)

adc= ADC(Pin(35))
adc.atten(ADC.ATTN_11DB)  #sets for a maximum input voltage of 3,6 volts
adc.width(ADC.WIDTH_10BIT)  #sets the bit width to 10 bits

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)

while True:
  adc_value= adc.read()

  pwm_21.duty(map(adc_value,0,1023,25,125)) 
  volts =(3.3*adc_value)/1023
  input_voltage = "The input voltage is {:0.2f} and the raw value is {:4d}" 
  print(input_voltage.format(volts,adc_value),end = "\r")