请在这里粘贴代码import sensor
import time
import display
from pyb import UART, LED
from pyb import Pin, Timer
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.LCD) #128x160
sensor.skip_frames(time=2000)
clock = time.clock()
lcd = display.SPIDisplay()
black = (32, 100, -128, 127, -128, 127)
uart = UART(3, 9600)
# 初始化定时器
timer = Timer(2, freq=50000)
light = timer.channel(1, Timer.PWM, pin=Pin("P6"))
light.pulse_width_percent(100) # 初始设置为100%占空比
# led_blue = LED(3)
# led_blue.on()
# 50kHz pin6 timer2 channel1
while True:
time.sleep(1000)
img = sensor.snapshot()
blobs = img.find_blobs([black], invert=True, roi=[0, 60, 128, 30])
if len(blobs) == 1:
# led_blue.on()
img.draw_rectangle([0, 60, 128, 30])
img.draw_rectangle(blobs[0][0:4], color=(255,0, 0))
lcd.write(img)
uart.write('#' + str(blobs[0].cx()) + '$')
print('#' + str(blobs[0].cx()) + '$')
elif len(blobs) == 0:
uart.write('S')
print('S')
2
2s4v
@2s4v
0
Reputation
1
Posts
33
Profile views
0
Followers
0
Following
Posts made by 2s4v
-
为什么这段代码脱机运行后补光灯不亮,去掉除了补光灯外的代码后又能亮