from machine import Pin, WDT
from time import sleep
# Create a Watchdog Timer with a 2-second timeout
watchdog_timer = WDT(timeout=2000)
# Define the button on pin 4
btn = Pin(4, Pin.IN, Pin.PULL_UP)
while True:
try:
# Print a message indicating the system is working well
print("System is working well")
sleep(1)
# Reset the Watchdog Timer
watchdog_timer.feed()
# Check the button state
if btn.value() == 0:
print('Error!')
# Attempt to divide by zero to trigger an error
x = 0 / 0
except ZeroDivisionError:
# Handle the division by zero error
print("Caught a division by zero error!")
# Reset the Watchdog Timer
watchdog_timer.feed()