#Reading analog voltage
from machine import Pin
from time import sleep #import sleep from time function in the libary
potPin=Pin(28) # pin 28 as an input.
myPot=machine.ADC(potPin) #analog to digital converter pin
ledPin=6 #GPIO 6
alarmLed=Pin(ledPin,Pin.OUT) #writes digital out to ledPin
#alarm=6 # alarm signal on Pin 6
#ledPin=Pin(alarm,Pin.OUT)
while True: #True is always true
# everything indented runs within the while statement
potVal=myPot.read_u16() # output a digital value using 16 bit ADC
print('potVal= ',potVal) # would be 0 to 65535 (max value =2^16 -1 because starts at 0 )
sleep(1)
#lowest reading = 0 --> 0 volts, highest reading 65535 -->3.3 Volts
#y=mx+c--> volts=(3.3/65535)*potVal
voltage=(3.3/65535)*potVal
print('Voltage= ',voltage, 'V')
sleep(1)
if voltage >=2:
alarmLed.value(1)
if voltage <2:
alarmLed.value(0)
# can also use toggle() if LED is on it will turn off and vice versa (e.g)
# myLED.toggle()
# sleep(.5)