我想请教一下,这个是无效语法是怎么回事呀,这是那个测距扩展版的语句,
-
import time, pyb, sensor, image, from machine import I2C from vl53l1x import VL53L1X from pyb import Servo UART LED sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(True) sensor.set_auto_whitebal(True) i2c = I2C(2) s1=Servo(1) distance = VL53L1X(i2c) uart = UART(3, 19200) led1 = pyb.LED(1) led2 = pyb.LED(2) led3 = pyb.LED(3) clock = time.clock() while True: print("range: mm ", distance.read()) time.sleep_ms(50) dis=distance.read() if 609<dis<675: print("wu")#0 elif 530<dis<540: led1.on() led2.on() led3.on() clock.tick() img = sensor.snapshot() for r in img.find_rects(threshold = 23000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) print(r.w()) print(r.h()) elif r.w() > r.h(): print("heng")#1 elif r.w()<r.h(): print("shu")#2 led1.off() led2.off() led3.off() elif 390<dis<400: led1.on() led2.on() led3.on() clock.tick() img = sensor.snapshot() for r in img.find_rects(threshold = 23000): img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) print(r.w()) print(r.h()) elif r.w() > r.h():#heng #<通信前移> elif 530<dis<540: print("shanghengxiashu")#3 elif 669<dis<670: print("shangxiaheng")#4 #<通信复位> elif r.w()<r.h(): print("shu") s1.angle(30) time.sleep_us(2000) elif 530<dis<540: print("shangshuxiaheng")#5 s1.angle(0) elif 669<dis<670: print("shangxiashu")#6 led1.off() led2.off() led3.off()
还有整体的还有错误,希望老师帮忙指正一下,万分感谢啦 非常着急
-
原因:缩进不对。
python中缩进是语法的一部分,必须正确。
-
啊!我就写了三种情况的这个老师可以帮忙指正一下吗