咱们这个串口输出的数据类型是哪种?要怎么转换才能让51单片机识别?谢谢了
3
3aoh
@3aoh
0
声望
3
楼层
339
资料浏览
0
粉丝
0
关注
3aoh 发布的帖子
-
请问用uart进行串口通信,要调用哪个函数才能读入
import sensor, image, time,pyb from pyb import UART import json thresholds = [(-5,35, 20, 60, 0, 40), # generic_red红_thresholds (10, 70, -40, -20, 0, 20), # generic_green绿_thresholds (15,45, 0, 35, -60, -30)] # generic_blue蓝_thresholds uart = UART(3, 9600) ledR= pyb.LED(1) ledG= pyb.LED(2) ledB= pyb.LED(3) led= pyb.LED(1) # Red LED = 1, Green LED = 2, Blue LED = 3, IR LEDs = 4. def R(): ledR.on() #亮灯 time.sleep(1000) #延时150ms ledR.off() #暗灯 time.sleep(500) def B(): ledB.on() #亮灯 time.sleep(1000) #延时150ms ledB.off() #暗灯 time.sleep(500) def G(): ledG.on() #亮灯 time.sleep(1000) #延时150ms ledG.off() #暗灯 time.sleep(500) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() def twoley(): while(True): clock.tick() img = sensor.snapshot() img.lens_corr(1.8)# for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color =(255,0,0)) message = code.payload() a=int(message) if a==123: while(True): R() G() B() print(a) uart.write('123') def yanshe(): while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) a=blob.cx() for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) b=blob.cx() for blob in img.find_blobs([thresholds[2]], pixels_threshold=200, area_threshold=200): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) c=blob.cx() time.sleep(500) if a<b : if a<c : if b<c : print(3,2,1) uart.write('out\n') else : print(2,3,1) else : print(2,1,3) else : if b<c : if a<c : print(3,1,2) else : print(1,3,2) else : print(1,2,3) while(True): flag=uart.read(0) if flag==1: twoley() elif flag==0: yanshe()