from machine import Pin,ADC
import time
import math

PIN_BATTERY = 32
led=Pin(2,Pin.OUT)
adc=ADC(Pin(PIN_BATTERY))
adc.atten(ADC.ATTN_11DB)
adc.width(ADC.WIDTH_12BIT)
batteryCoefficient = 4
led.value(0)

for n in range(10):
    adcValue=adc.read()
    batteryVoltage = (adcValue / 4096.0  * 3.9 ) * batteryCoefficient
    print("ADC value:",adcValue,"\tVoltage :",batteryVoltage);
    if int(batteryVoltage) >> 2:
        led.value(0)
        print('battery: On')
    else:
        led.value(1)
        print('battery: Off')
    time.sleep_ms(1000)