外部中断程序单独可以运行,但是加入sensor.snapshot()函数之后就不行了?
-
我想用两个中断控制两个颜色的灯,while里输出hello world时程序可以正常运行(即下面代码中注释掉的while)。但是加入sensor.snapshot()输出图像时就会报错,错误类型MemoryError: memory allocation failed, heap is locked
import sensor, image, time,pyb,utime from pyb import Pin, ExtInt import micropython micropython.alloc_emergency_exception_buf(100) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) clock = time.clock() a=b=0 blue = pyb.LED(3) green = pyb.LED(2) stop_flag = 1 def start(line): stop_flag = 0 blue.off() green.on() print('start',) def stop(line): blue.on() green.off() print('stop') sta = ExtInt(Pin('P4'),ExtInt.IRQ_RISING,Pin.PULL_NONE, start) sto = ExtInt(Pin('P5'),ExtInt.IRQ_RISING,Pin.PULL_NONE, stop) while(True): clock.tick() img = sensor.snapshot() '''n=0 while True: utime.sleep_ms(1000) n=n+1 print('hello world',n)'''