logo

为何定时器和拍照功能放一起会导致程序跑死?【最简单的例程,星瞳首问】

2019-04-23 22:50
O
_14773641456

如题。

具体代码和截图见下。

import time
import sensor#引入感光元件的模块
from pyb import Pin, Timer

sensor.reset()#初始化感光元件
sensor.set_pixformat(sensor.RGB565)#设置为彩色
sensor.set_framesize(sensor.QVGA)#设置图像的大小
sensor.skip_frames()#跳过n张照片,在更改设置后,跳过一些帧,等待感光元件变稳定。


def tick(timer):            # we will receive the timer object when being called
    print("Timer callback")

tim = Timer(4, freq=100)      # create a timer object using timer 4 - trigger at 1Hz
tim.callback(tick)          # set the callback to our tick function

while (True):
    time.sleep(1000)
    img = sensor.snapshot()#拍摄一张照片,img为一个image对象'''
3f29c6e4-416f-44ae-b53c-827da7da0ddc.png
cadc6704-8388-469b-b537-76cf388846a1.png
56c7271d-cf18-4205-942e-9cb4c8264955.png

请各位大佬赐教。或者谁做的实验或者小项目用过这两个组合的发我一份呀。^-^