You need to add the following lines to your python code:
Code: Select all
import micropython
micropython.alloc_emergency_exception_buf(100)
Code: Select all
import pyb
import micropython
class Heartbeat(object):
def __init__(self):
self.tick = 0
self.led = pyb.LED(4) # 4 = Blue
tim = pyb.Timer(4)
tim.init(freq=10)
tim.callback(self.heartbeat_cb)
def heartbeat_cb(self, tim):
if self.tick <= 3:
led.toggle()
self.tick = (self.tick + 1) % 10
micropython.alloc_emergency_exception_buf(100)
Heartbeat()
Code: Select all
>>> import heartbeat_irq
Uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
File "0://heartbeat_irq.py", line 15, in heartbeat_cb
NameError: name 'led' is not defined