import utime as time
from machine import Pin, WDT
print('Press the button on GPIO-16 to enable WDT.')
button = Pin( 16, mode=Pin.IN, pull=Pin.PULL_UP )
time.sleep_ms(1000)
wdt = None
if button.value() == 0:
# enable WDT with timeout of 2000 msec
wdt = WDT(timeout=20000)
# Note that once the WDT is running the timeout cannot be
# changed and it cannot be stopped either.
if wdt is None:
print('WDT is disabled.')
try:
while wdt is not None:
# feed the WDT to prevent it from resetting the system.
print('feed WDT @{} ms'.format( time.ticks_ms() ) )
wdt.feed()
time.sleep(1.0)
except KeyboardInterrupt:
pass