from machine import Pin, Timer, ADC
import utime
# import machine
# led = Pin(25, Pin.OUT)
freqValue = 1
dutyCyc = 20 # percent
on_start = 0
led = Pin("LED", Pin.OUT)
adc = ADC(Pin(26)) # create ADC object on ADC pin
timer = Timer()
CountDown = Timer()
button = Pin(11, Pin.IN, Pin.PULL_DOWN)
led.on()
delta = 0
onTIMEms = 1000
def blink(on_start):
# if 1: #button.value():
#if True:
led.toggle()
if led():
on_start = 1
print("on_start is",on_start)
timer.init(freq=freqValue, mode=Timer.PERIODIC, callback=blink(on_start))
while 1:
if on_start:
on_start = 0
print("Duty Cycle is",dutyCyc)
onTIMEms = ((dutyCyc*10)/freqValue)
startms = utime.ticks_ms() # get millisecond counter
delta = utime.ticks_diff(time.ticks_ms(), startms) # compute time difference
if (delta >= onTIMEms):
led.off()
# adc.read_u16() # read value, 0-65535 across voltage range 0.0v - 3.3v