from pyb import UART
uart = UART(3, 9600, timeout_char=1000) # i使用给定波特率初始化
uart.init(9600, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
# Snapshot Example
#
# Note: You will need an SD card to run this example.
#
# You can use your OpenMV Cam to save image files.
import sensor, image, pyb,sensor, gif,time,utime
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others)
sensor.skip_frames(time = 2000) # Let new settings take affect.
while(True):
if not uart.any():
# 啥事儿不干
sensor.snapshot()
time.sleep(100)
else:
a=uart.readline()
print(a)
if a=='12\n':
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()
print("You're on camera!")
sensor.snapshot().save("example_tupian.jpg") # or "example.bmp" (or others)
pyb.LED(BLUE_LED_PIN).off()
print("Done! Reset the camera to see the saved image.")
else:
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()
g = gif.Gif("example.gif", loop=True)
print("You're on camera2!")
for i in range(300):
# clock.avg() returns the milliseconds between frames - gif delay is in
g.add_frame(sensor.snapshot()) # centiseconds.
g.close()
pyb.LED(BLUE_LED_PIN).off()
print("Done! Reset the camera to see the saved recording.")
![0_1554819102607_QQ图片20190409221130.png](https://fcdn.singtown.com/52e3026f-375b-43fe-8a5c-747df184bccc.png)
不管怎么输入a 都是选择了else