| 123456789101112131415161718 |
- import time
- from machine import ADC,Pin
- adc = ADC(Pin(34), atten=ADC.ATTN_11DB) # create an ADC object acting on a pin
- led = Pin(18, Pin.OUT)
- def ctrl_led(current):
- if current > 30000:
- led.off()
- if current < 27000:
- led.on()
- while True:
- val = adc.read_u16() # read a raw analog value in the range 0-65535
- ctrl_led(val)
- wdat = 'val:{}'.format(val)
- print(wdat, end='\x08' * len(wdat))
- time.sleep(0.03)
- print(' ' * len(wdat), end='\x08' * len(wdat))
|