pixformat is not supported是怎么回事?
-
import pyb, sensor, image, math, time, utimesensor.reset()#openmv初始化sensor.set_framesize(sensor.QVGA)#设置图像大小sensor.set_pixformat(sensor.GRAYSCALE)from pyb import Pinwave_echo_pin = Pin('P7', Pin.IN , Pin.PULL_NONE)wave_trig_pin = Pin('P8', Pin.OUT_PP, Pin.PULL_DOWN)wave_distance = 0tim_counter = 0flag_wave = 0#超声波启动def wave_start(): wave_trig_pin.value(1) utime.sleep_us(15) wave_trig_pin.value(0)#超声波距离计算def wave_distance_calculation(): #全局变量声明 global tim_counter #频率f为0.2MHZ 高电平时间t=计数值1/f wave_distance = tim_counter5*0.017 #输出最终的测量距离(单位cm) print('wave_distance',wave_distance)#超声波数据处理def wave_distance_process(): global flag_wave if(flag_wave == 0): wave_start() if(flag_wave == 2): wave_distance_calculation() flag_wave = 0#配置定时器tim =pyb.Timer(1, prescaler=720, period=65535) #相当于freq=0.2M#外部中断配置def callback(line): global flag_wave,tim_counter #上升沿触发处理 if(wave_echo_pin.value()): tim.init(prescaler=720, period=65535) flag_wave = 1 #下降沿 else: tim.deinit() tim_counter = tim.counter() tim.counter(0) extint.disable() flag_wave = 2#中断配置extint = pyb.ExtInt(wave_echo_pin, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_DOWN, callback)while(True): wave_distance_process() time.sleep(100) for i in range(10): img = sensor.snapshot() for j in range(100): img.draw_string(50, 0, "space:",color=[255,0,0]) img.draw_string(50, 10, str(wave_distance),color=[255,0,0]) img.draw_string(100, 10, "CM",color=[255,0,0])
-
-
另外,代码请使用格式上传,具体请看 玩转星瞳论坛
-
基本上确定是中断的问题,你运行hello world看看
-
@yuan
超声波测距print出来的全部是0,就算没加屏幕显示都不对,这是啥原因呢?