我这个代码一直报错,我在论坛里也搜不到为什么,本人小白,但这个有点急,希望有人能帮帮忙
-
# Line Drawing # # This example shows off drawing lines on the OpenMV Cam. import sensor, image, time, pyb gainceiling=16 constrast=0 brightness=0 saturation=0 gainceiling_flag=1 constrast_flag=1 brightness_flag=1 saturation_flag=1 sensor.reset() sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE... sensor.set_framesize(sensor.QVGA) # or QQVGA... sensor.skip_frames(time = 2000) clock = time.clock() p0_in = Pin('P0', Pin.IN, Pin.PULL_UP) p1_in = Pin('P1', Pin.IN, Pin.PULL_UP) p2_in = Pin('P2', Pin.IN, Pin.PULL_UP) p3_in = Pin('P3', Pin.IN, Pin.PULL_UP) def Key_Scan(): gainceiling_flag=p0_in.value() # get value, 0 or 1 constrast_flag=p1_in.value() # get value, 0 or 1 brightness_flag=p2_in.value() # get value, 0 or 1 saturation_flag=p3_in.value() # get value, 0 or 1 if(gainceiling_flag==0) time.sleep(0.02) #延时20ms,防抖动 if (gainceiling_flag==0): #再次判断是否被按下 while (gainceiling_flag==0): #等待松手 pass gainceiling=gainceiling*2 if(gainceiling>128) gainceiling=2 if(constrast_flag==0) time.sleep(0.02) #延时20ms,防抖动 if (constrast_flag==0): #再次判断是否被按下 while (constrast_flag==0): #等待松手 pass constrast=constrast+1 if(constrast>3) constrast=-3 if(brightness_flag==0) time.sleep(0.02) #延时20ms,防抖动 if (brightness_flag==0): #再次判断是否被按下 while (brightness_flag==0): #等待松手 pass brightness=brightness+1 if(brightness>3) brightness=-3 if(saturation_flag==0) time.sleep(0.02) #延时20ms,防抖动 if (saturation_flag==0): #再次判断是否被按下 while (saturation_flag==0): #等待松手 pass saturation=saturation+1 if(saturation>3) saturation=-3 sensor.set_gainceiling(gainceiling) sensor.set_contrast(constrast) sensor.set_brightness(brightness) sensor.set_saturation(saturation) while(True): clock.tick() Key_Scan() img = sensor.snapshot()
请在这里粘贴代码
-
报错很明显啊,语法错误,30行后面都没加冒号
-
还有在最开始加一句 from pyb import Pin
-
还有应该把6行到13行的一堆变量放到25行的函数里面去,不然是全局变量。
-
你这个第30行的按键判断不对,应该一直用p0_in.value(),否则是只读引脚一次,啥用没有。
不只是第30行。