openmv串口如何发送字符串 数字 整形数组

 发送字符串简单:直接write(“........”)

发送一个数字一个字符可以write(k)

int kk=1;write(kk);

发送数字数组可以: kk=[51,100]
                                    uart.write(bytes(kk)) 

import sensor, image, time, math, pyb
from machine import UART
import display

 
 
 
#用来调binary值
NUMBER1=51
NUMBER2=255
#这两变量是用来你调阈值,是为了适应在不同场合光线下刚好把黑色与白色分开 ,借助按键调整这个阈值就可以完成现场调试
turnGRAYSCALE_THRESHOLD = [(NUMBER1, NUMBER2)]
GRAYSCALE_THRESHOLD =[(0,0)]
# 每个roi为(x, y, w, h),线检测算法将尝试找到每个roi中最大的blob的质心。
# 然后用不同的权重对质心的x位置求平均值,其中最大的权重分配给靠近图像底部的roi,
# 较小的权重分配给下一个roi,以此类推。
 
rois = [(0, 100, 160, 20), (0, 50, 160, 20), (0, 0, 160, 20)]
# roi代表三个取样区域,(x,y,w,h,weight),代表左上顶点(x,y)宽高分别为w和h的矩形,
# weight为当前矩形的权值。注意本例程采用的QQVGA图像大小为160x120,roi即把图像横分成三个矩形。
# 三个矩形的阈值要根据实际情况进行调整,离机器人视野最近的矩形权值要最大,
# 如上图的最下方的矩形,即(0, 100, 160, 20, 0.7)
 
# 初始化sensor
 
sensor.reset()
# 设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种
sensor.set_pixformat(sensor.GRAYSCALE)  # use grayscale.
# 设置图像像素大小
sensor.set_framesize(sensor.QQVGA)  # use QQVGA for speed.
# 让新的设置生效。
sensor.skip_frames(time=2000)  # Let new settings take effect.
# 颜色跟踪必须关闭自动增益
sensor.set_auto_gain(False)  # must be turned off for color tracking
# 颜色跟踪必须关闭白平衡
sensor.set_auto_whitebal(False)  # must be turned off for color tracking
# 跟踪FPS帧率
lcd = display.SPIDisplay()  # Initialize the lcd screen.
kk='y'
sensor.set_vflip(1)
sensor.set_hmirror(1)
clock = time.clock()  # Tracks FPS.
largest2_blob=0
deflection_angle = 0  # Initialize deflection_angle outside of conditional blocks
uart = UART(3,9600,timeout_char=1000)
while True:
    turnGRAYSCALE_THRESHOLD = [(NUMBER1, NUMBER2)]
    clock.tick()  # Track elapsed milliseconds between snapshots.
    img = sensor.snapshot()  # Capture an image.
   
    img.binary(turnGRAYSCALE_THRESHOLD)
 
    largest_blob = None
    #largest2_blob = None
    #largest3_blob = None
 
    # Track lines in each defined ROI.
    #blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=rois[0], merge=True)
    #if blobs:
    #    largest_blob = max(blobs, key=lambda b: b.pixels())
 
    blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=rois[1], merge=True)
    if blobs:
        largest2_blob = max(blobs, key=lambda b: b.pixels())
    #
    #blobs = img.find_blobs(GRAYSCALE_THRESHOLD, roi=rois[2], merge=True)
    #if blobs:
    #    largest3_blob = max(blobs, key=lambda b: b.pixels())
 
    # Calculate deflection_angle based on largest2_blob.cx() - 79
    #通过计算图像中心点x与块中心点x的差判断偏移
    pianyi = 0
    if largest2_blob:
        pianyi = largest2_blob.cx() - 79
        img.draw_rectangle(largest2_blob.rect(),color=(0));
        if -5 <= pianyi < 5:
            deflection_angle = 0
        elif -15 <= pianyi < -5:
            deflection_angle = -2
        elif 5 <= pianyi < 15:
            deflection_angle = 2
        elif -30 <= pianyi < -15:
            deflection_angle = -3
        elif 15 <= pianyi < 30:
            deflection_angle = 3
        elif -50 <= pianyi < -30:
            deflection_angle = -5
        elif 30 <= pianyi < 50:
            deflection_angle = 5
 
   
    if NUMBER1>255:
        NUMBER1=255
    if NUMBER2>255:
        NUMBER2=255
    if NUMBER1<0:
        NUMBER1=0
    if NUMBER2<0:
        NUMBER2=0

    kk=[NUMBER1,NUMBER2]
    uart.write(bytes(kk))    
    lcd.write(img)  # Take a picture and display the image.

    byte=uart.read(1)
    if byte :
        print(byte)
        if byte ==b'a':
            NUMBER1=NUMBER1+5
        if byte ==b'b':
            NUMBER2=NUMBER2+5
        if byte ==b'c':
            NUMBER1=NUMBER1-5
        if byte ==b'd':
            NUMBER2=NUMBER2-5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

广药门徒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值