用的是uart. write函数
发送的数据是bytearray函数赋值的十六进制数据
M
mgbr 发布的帖子
-
运行时报错显示memoryerror,是程序的问题还是代码过长还是内存不够?
import sensor, image, time, math, pyb from pyb import Pin from pyb import LED from pyb import UART thresholds = [(23, 50, -2, 75, -28, 59), (17, 57, -53, -11, -17, 33), (8, 43, -15, 28, -53, 2)] p_in1 = Pin('P7', Pin.IN, Pin.PULL_UP) p_in2 = Pin('P8', Pin.IN, Pin.PULL_UP) p_in3 = Pin('P6', Pin.IN, Pin.PULL_UP) sss=100 vvv=0 zzz=0 aa = [0 for x in range(0,6)] bb = [0 for x in range(0,6)] cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] count = 0 jiaodu1=0 jiaodu2=0 x1=0 x2=0 cccx=0 cccy=0 uart = UART(3, 9600) uart.init(9600, bits=8, parity=None, stop=1) uartp = UART(1, 9600) uartp.init(9600, bits=8, parity=None, stop=1) A0=bytearray([0xFF,0x09,0x00,0x00,0x00]) A1=bytearray([0xFF,0x09,0x00,0x01,0x00]) A2=bytearray([0xFF,0x09,0x00,0x02,0x00]) A3=bytearray([0xFF,0x09,0x00,0x03,0x00]) A4=bytearray([0xFF,0x09,0x00,0x04,0x00]) A5=bytearray([0xFF,0x09,0x00,0x05,0x00]) A6=bytearray([0xFF,0x09,0x00,0x06,0x00]) A7=bytearray([0xFF,0x09,0x00,0x07,0x00]) A8=bytearray([0xFF,0x09,0x00,0x08,0x00]) A9=bytearray([0xFF,0x09,0x00,0x09,0x00]) A10=bytearray([0xFF,0x09,0x00,0x0a,0x00]) A11=bytearray([0xFF,0x09,0x00,0x0b,0x00]) A12=bytearray([0xFF,0x09,0x00,0x0c,0x00]) A13=bytearray([0xFF,0x09,0x00,0x0d,0x00]) A14=bytearray([0xFF,0x09,0x00,0x0e,0x00]) A15=bytearray([0xFF,0x09,0x00,0x0f,0x00]) A16=bytearray([0xFF,0x01,0x00,0xe8,0x03]) A17=bytearray([0xFF,0x01,0x01,0xe8,0x03]) A18=bytearray([0xFF,0x01,0x02,0xe8,0x03]) A19=bytearray([0xFF,0x01,0x04,0xdc,0x05]) A20=bytearray([0xFF,0x02,0x00,0xa5,0x03]) A21=bytearray([0xFF,0x02,0x01,0x6c,0x05]) A50=bytearray([0xFF,0x02,0x02,0xe5,0x08]) A22=bytearray([0xFF,0x02,0x00,0xbb,0x03]) A23=bytearray([0xFF,0x02,0x01,0x8e,0x04]) A24=bytearray([0xFF,0x02,0x02,0x3f,0x08]) A25=bytearray([0xFF,0x02,0x01,0x41,0x03]) A26=bytearray([0xFF,0x02,0x02,0x54,0x09]) A27=bytearray([0xFF,0x02,0x01,0xc6,0x04]) A28=bytearray([0xFF,0x02,0x00,0x14,0x03]) A29=bytearray([0xFF,0x02,0x01,0x41,0x03]) A30=bytearray([0xFF,0x02,0x02,0xc4,0x09]) A31=bytearray([0xFF,0x02,0x01,0x1f,0x04]) A32=bytearray([0xFF,0x02,0x02,0x54,0x09]) A33=bytearray([0xFF,0x02,0x00,0x63,0x02]) A34=bytearray([0xFF,0x02,0x01,0x09,0x03]) A35=bytearray([0xFF,0x02,0x02,0x54,0x09]) A36=bytearray([0xFF,0x02,0x01,0x41,0x03]) A37=bytearray([0xFF,0x02,0x01,0x84,0x03]) A38=bytearray([0xFF,0x02,0x00,0x6d,0x04]) A39=bytearray([0xFF,0x02,0x01,0x1f,0x04]) A40=bytearray([0xFF,0x02,0x02,0xae,0x08]) A41=bytearray([0xFF,0x02,0x00,0x14,0x03]) A42=bytearray([0xFF,0x02,0x02,0x54,0x09]) A60=bytearray([0xFF,0x02,0x04,0x09,0x03]) A61=bytearray([0xFF,0x02,0x01,0x29,0x06]) A62=bytearray([0xFF,0x02,0x02,0xfd,0x04]) A63=bytearray([0xFF,0x02,0x00,0xbb,0x03]) A64=bytearray([0xFF,0x02,0x00,0x83,0x05]) A65=bytearray([0xFF,0x02,0x01,0xdc,0x04]) A66=bytearray([0xFF,0x02,0x02,0x82,0x06]) A80=bytearray([0xFF,0x02,0x02,0xba,0x06]) A81=bytearray([0xFF,0x02,0x02,0xdb,0x06]) A82=bytearray([0xFF,0x02,0x01,0xa5,0x03]) A83=bytearray([0xFF,0x02,0x01,0xdc,0x03]) A84=bytearray([0xFF,0x02,0x01,0x9a,0x03]) A88='t0.txt="43214444321"' A89='t0.txt="43124444312"' A90='t0.txt="42134444213"' A91='t0.txt="42314444231"' A92='t0.txt="41234444123"' A93='t0.txt="41324444132"' A100='t0.txt=' A99=bytearray([0xFF,0xFF,0xFF]) while(True): value1 = p_in1.value() value2 = p_in2.value() value3 = p_in3.value() pyb.delay(2000) if sss==100: uart.write(A0) sss=0 print(sss) while(value1 ==0 and value2 ==0 and value3 ==0 and sss==0 ): value1 = p_in1.value() value2 = p_in2.value() value3 = p_in3.value() pyb.delay (200) print(sss) while(value1 ==1 and value2 ==1 and value3 ==1 and sss==0 ): led = LED(2) led.toggle() led.on() uart.write(A16) uart.write(A17) uart.write(A18) uart.write(A19) uart.write(A38) uart.write(A20) uart.write(A21) uart.write(A50) sss=1 print(sss) while(sss==1): sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) sensor.set_windowing((400, 400)) sensor.skip_frames(time = 200) sensor.set_auto_gain(False) clock = time.clock() clock.tick() img = sensor.snapshot() for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color = 127) aa=code.payload() print(aa) sensor.skip_frames(10) uart.write(A0) if (aa[0]=='3' and aa[1]=='2' and aa[2]=='1'): uartp.write(A88) pyb.delay(500) uartp.write(A99) if aa[0]=='3' and aa[1]=='1' and aa[2]=='2': uartp.write(A89) pyb.delay(500) uartp.write(A99) if aa[0]=='2' and aa[1]=='1' and aa[2]=='3': uartp.write(A90) pyb.delay(500) uartp.write(A99) if aa[0]=='2' and aa[1]=='3' and aa[2]=='1': uartp.write(A91) pyb.delay(500) uartp.write(A99) if aa[0]=='1' and aa[1]=='2' and aa[2]=='3': uartp.write(A92) pyb.delay(500) uartp.write(A99) if aa[0]=='1' and aa[1]=='3' and aa[2]=='2': uartp.write(A93) pyb.delay(500) uartp.write(A99) sss=2 print(sss) while(sss==2): value1 = p_in1.value() value2 = p_in2.value() value3 = p_in3.value() print(sss) if value1 == 1 and value2 == 0 and value3 == 0 and sss==2 : uart.write(A33) pyb.delay(1500) uart.write(A31) pyb.delay(500) uart.write(A32) pyb.delay(500) uart.write(A34) uart.write(A35) pyb.delay(6000) led = LED(1) led.toggle() led.on() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) n=0 codem = 0 pixelsm = 0 codemlist = [0 for x in range(0,5)] while (sss==2): img = sensor.snapshot() clock = time.clock() clock.tick() for blob in img.find_blobs(thresholds, pixels_threshold=3000, area_threshold=3000): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) if blob.pixels() > pixelsm: pixelsm = blob.pixels () codem = blob.code() print(codem) print(pixelsm) codemlist[n] = codem n=n+1 if n==5 and codemlist[0] == codemlist[1] == codemlist[2] == codemlist[3] == codemlist[4]: bb[count] = codemlist[4] if bb[count]==4: bb[count]='3' if bb[count]==2: bb[count]='2' if bb[count]==1: bb[count]='1' n=0 codemlist = [0 for x in range(0,5)] print(bb[0]) sss=3 if n==5: n=0 if sss==3: uart.write(A27) pyb.delay(500) uart.write(A28) pyb.delay(500) uart.write(A29) uart.write(A30) pyb.delay(5000) count=1 sss=4 if value1 == 1 and value2 == 0 and value3 == 0 and sss==4: led = LED(1) led.toggle() led.on() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False,value=100) sensor.set_auto_whitebal(False,value=100) codem = 0 pixelsm = 0 codemlist = [0 for x in range(0,5)] n=0 while (sss==4): img = sensor.snapshot() clock = time.clock() clock.tick() for blob in img.find_blobs(thresholds, pixels_threshold=3000, area_threshold=3000): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) if blob.pixels() > pixelsm: pixelsm = blob.pixels () codem = blob.code() print(codem) print(pixelsm) codemlist[n] = codem n+=1 if n==5 and codemlist[0] == codemlist[1] == codemlist[2] == codemlist[3] == codemlist[4]: bb[count] = codemlist[4] if bb[count]==4: bb[count]='3' if bb[count]==2: bb[count]='2' if bb[count]==1: bb[count]='1' n=0 codemlist = [0 for x in range(0,5)] sss=5 if n==5: n=0 if sss==5: uart.write(A23) pyb.delay(800) uart.write(A24) pyb.delay(800) uart.write(A22) uart.write(A25) uart.write(A26) pyb.delay(5000) count=2 sss=6 if value1 == 1 and value2 == 0 and value3 == 0 and sss==6: led = LED(1) led.toggle() led.on() sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False,value=100) sensor.set_auto_whitebal(False,value=100) codem = 0 pixelsm = 0 codemlist = [0 for x in range(0,5)] n=0 while (sss==6): img = sensor.snapshot() clock = time.clock() clock.tick() for blob in img.find_blobs(thresholds, pixels_threshold=3000, area_threshold=3000): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) if blob.pixels() > pixelsm: pixelsm = blob.pixels () codem = blob.code() print(codem) print(pixelsm) codemlist[n] = codem n+=1 if n==5 and codemlist[0] == codemlist[1] == codemlist[2] == codemlist[3] == codemlist[4]: bb[count] = codemlist[4] if bb[count]==4: bb[count]='3' if bb[count]==2: bb[count]='2' if bb[count]==1: bb[count]='1' n=0 codemlist = [0 for x in range(0,5)] print(bb) print(aa) sss=7 if n==5: n=0 count=0 if bb[0]==bb[1] and bb[1]==bb[2]: bb[0]='1' bb[1]='2' bb[2]='3' if bb[0]==0: bb[0]='1' if bb[1]==0: bb[1]='2' if bb[2]==0: bb[2]='3' if bb[0]==bb[1]: bb[0]=str(6-int(bb[0])-int(bb[2])) if bb[0]==bb[2]: bb[2]=str(6-int(bb[0])-int(bb[1])) if bb[1]==bb[2]: bb[1]=str(6-int(bb[0])-int(bb[1])) print(bb) print(aa) if sss==7: print(sss) if aa[0]==bb[0]: uart.write(A4) pyb.delay(6000) if aa[0]==bb[1]: uart.write(A5) pyb.delay(6000) if aa[0]==bb[2]: uart.write(A36) pyb.delay(500) uart.write(A6) pyb.delay(6000) if aa[0]=='1': uart.write(A8) pyb.delay(7000) if aa[0]=='2': uart.write(A9) pyb.delay(7000) if aa[0]=='3': uart.write(A10) pyb.delay(7000) if aa[1]==bb[0]: uart.write(A4) pyb.delay(6000) if aa[1]==bb[1]: uart.write(A5) pyb.delay(6000) if aa[1]==bb[2]: uart.write(A6) pyb.delay(6000) if aa[1]=='1': uart.write(A8) pyb.delay(7000) if aa[1]=='2': uart.write(A9) pyb.delay(7000) if aa[1]=='3': uart.write(A10) pyb.delay(7000) if aa[2]==bb[0]: uart.write(A4) pyb.delay(6000) if aa[2]==bb[1]: uart.write(A5) pyb.delay(6000) if aa[2]==bb[2]: uart.write(A6) pyb.delay(6000) if aa[2]=='1': uart.write(A8) pyb.delay(7000) if aa[2]=='2': uart.write(A9) pyb.delay(7000) if aa[2]=='3': uart.write(A10) pyb.delay(7000) uart.write(A0) pyb.delay(3000) sss=8 while(value1 ==1 and value2 ==0 and value3 ==0 and sss==8 ): value1 = p_in1.value() value2 = p_in2.value() value3 = p_in3.value() pyb.delay (200) print(sss) if sss==8 and value1 == 0 and value2 == 0 and value3 == 1: print('werfrwg') if aa[0]=='1': uart.write(A13) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==0): img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=1 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=10-int((88-cc[1])/10) jiaodu2=63+int((51-dd [1])/3) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(500) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) print('qrqqer') if aa[0]=='2': uart.write(A12) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==0): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=1 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=27-int((71-cc[1])/7) jiaodu2=69+int((59-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A81) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[0]=='3': uart.write(A11) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==0): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=1 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=40-int((70-cc[1])/7) jiaodu2=59+int((75-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[1]=='1': uart.write(A13) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==1): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=2 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=10-int((88-cc[1])/10) jiaodu2=63+int((51-dd [1])/3) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[1]=='2': uart.write(A12) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==1): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=2 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=27-int((71-cc[1])/7) jiaodu2=69+int((59-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A81) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[1]=='3': uart.write(A11) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==1): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=2 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=40-int((70-cc[1])/7) jiaodu2=59+int((75-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[2]=='1': uart.write(A13) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==2): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=3 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=10-int((88-cc[1])/10) jiaodu2=63+int((51-dd [1])/3) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[2]=='2': uart.write(A12) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==2): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=3 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=27-int((71-cc[1])/7) jiaodu2=69+int((59-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A81) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) if aa[2]=='3': uart.write(A11) pyb.delay(7000) sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) while(vvv==2): clock = time.clock() img = sensor.snapshot() for c in img.find_circles(threshold = 2800, x_margin = 100, y_margin = 100, r_margin = 100,r_min = 10, r_max = 200, r_step = 10): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) cc[cccx]=c.x() dd[cccy]=c.y() print(cc[cccx],dd[cccy]) print(cccx) cccx+=1 cccy+=1 pyb.delay(200) if(cccx==3): if(abs(cc[0]-cc[1])<=3 and abs(dd[0]-dd[1])<=3 and abs(cc[1]-cc[2])<=3 and abs(dd[2]-dd[1])<=3): print(cc[1],dd[1]) vvv=3 else: cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 jiaodu1=40-int((70-cc[1])/7) jiaodu2=59+int((75-dd [1])/4) x1=int((jiaodu1/45)*500+500) x2=int((jiaodu2/45)*500+500) cc = [0 for x in range(0,6)] dd = [0 for x in range(0,6)] cccx=0 cccy=0 y1=x1%256 y2=x2%256 z1=int((x1-y1)/256) z2=int((x2-y2)/256) b1=bytearray([0xFF,0x02,0x00,y1,z1]) b2=bytearray([0xFF,0x02,0x01,y2,z2]) uart.write(b1) pyb.delay(300) uart.write(b2) pyb.delay(300) uart.write(A80) pyb.delay(700) uart.write(A60) pyb.delay(500) uart.write(A61) pyb.delay(500) uart.write(A62) pyb.delay(500) uart.write(A63) pyb.delay(500) uart.write(A64) pyb.delay(500) uart.write(A65) pyb.delay(500) uart.write(A66) pyb.delay(500) sss=9 if value1==0 and value2==0 and value3==1 and sss==9: bb = [0 for x in range(0,6)] uart.write(A38) pyb.delay(800) uart.write(A39) pyb.delay(500) uart.write(A40) pyb.delay(500) uart.write(A41) pyb.delay(500) uart.write(A42) pyb.delay(500) uart.write(A31) pyb.delay(500) uart.write(A32) pyb.delay(500) uart.write(A33) pyb.delay(300) uart.write(A37) uart.write(A35) pyb.delay(6000) led = LED(1) led.toggle() led.on() sensor.reset() sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False,value=100) sensor.set_auto_whitebal(False,value=100) codem = 0 pixelsm = 0 codemlist = [0 for x in range(0,5)] n=0 while (sss==9): img = sensor.snapshot() clock = time.clock() clock.tick() for blob in img.find_blobs(thresholds, pixels_threshold=3000, area_threshold=3000): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) if blob.pixels() > pixelsm: pixelsm = blob.pixels () codem = blob.code() print(codem) print(pixelsm) codemlist[n] = codem n+=1 if n==5 and codemlist[0] == codemlist[1] == codemlist[2] == codemlist[3] == codemlist[4]: bb[count] = codemlist[4] if bb[count]==4: bb[count]='3' if bb[count]==2: bb[count]='2' if bb[count]==1: bb[count]='1' n=0 codemlist = [0 for x in range(0,5)] sss=10 if n==5: n=0 if sss==10: uart.write(A27) pyb.delay(300) uart.write(A28) pyb.delay(300) uart.write(A37) uart.write(A30) pyb.delay(5000) count=1 sss=11 if sss==11: led = LED(1)