logo

在判断颜色以后亮红灯

2020-07-10 21:59
Z
fopl
import sensor, image, time

sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)               # Create a clock object to track the FPS.

ROI=(80,30,15,15)

while(True):
    img = sensor.snapshot()         # Take a picture and return the image.
    statistics=img.get_statistics(roi=ROI)
    color_l=statistics.l_mode()
    color_a=statistics.a_mode()
    color_b=statistics.b_mode()
    print(color_l,color_a,color_b)
    img.draw_rectangle(ROI)
   red_led = pyb.LED(1)
    while(color_l>50):
        red_led.on()
    while(color_l<=50):
        red_led.off()

这样写好像红灯不会亮,应该怎么写才能使用 color_l大于50的时候亮红灯

2020-07-13 12:43
I
网红小智智 星瞳科技
if color_l>50:
    red_led.on()
else:
    red_led.off()
2020-07-13 20:59
Z
fopl

出现错误 NameError:name'red_led"is not defined

2020-07-13 21:41
Z
fopl

@kidswong999 # Untitled - By: Administrator - 周三 7月 8 2020

import sensor, image, time,pyb

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 2000)

clock = time.clock()

while(True):

clock.tick()

img = sensor.snapshot()

print(clock.fps())

import sensor, image, time

sensor.reset() # 初始化摄像头

sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(10) # 跳过10帧,使新设置生效

sensor.set_auto_whitebal(False) # Create a clock object to track the FPS.

ROI=(228,55,15,15)

while(True):

img = sensor.snapshot() # Take a picture and return the image.

statistics=img.get_statistics(roi=ROI)

color_l=statistics.l_mode()

color_a=statistics.a_mode()

color_b=statistics.b_mode()

print(color_l,color_a,color_b)

img.draw_rectangle(ROI)

if color_l>50:

redled.on()

else:

ledled.off()

灯不会亮,是还要怎么调用吗

2020-07-14 13:46
I
网红小智智 星瞳科技

你需要从头学一下编程。变量,if,循环,缩进,都需要学。

import sensor, image, time
import pyb

sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(10) # 跳过10帧,使新设置生效
sensor.set_auto_whitebal(False)               # Create a clock object to track the FPS.

ROI=(80,30,15,15)
redled = pyb.LED(1)

while(True):
    img = sensor.snapshot()         # Take a picture and return the image.
    statistics=img.get_statistics(roi=ROI)
    color_l=statistics.l_mode()
    color_a=statistics.a_mode()
    color_b=statistics.b_mode()
    print(color_l,color_a,color_b)
    img.draw_rectangle(ROI)

    if color_l>50:
       redled.on()
    else:
       redled.off()
2020-07-14 20:25
Z
fopl

有好的推荐吗,应该从那开始学,谢谢!

2020-07-15 17:13
I
网红小智智 星瞳科技

https://singtown.com/learn/50061/

2020-07-19 17:51
Z
fopl

@kidswong999 试了一下还是不会亮,以帮我写一个做参考吗,谢谢,就是上面的程式,固定点的颜色的值大于50后亮红灯

2020-07-20 16:17
I
网红小智智 星瞳科技

我上面的代码可以运行,可以亮。

2020-07-23 23:49
Z
fopl

那我的为什么亮不了,是要在那个页面编辑才行吗

2020-07-26 23:36
I
网红小智智 星瞳科技

我发的代码是可以亮灯的。如果你测试不行,直接联系客服寄回测试。