logo

为什么识别不了输入的a来拍照呀,

2019-04-09 22:12
7
_5g6h
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.")
52e3026f-375b-43fe-8a5c-747df184bccc.png

不管怎么输入a 都是选择了else

2019-04-10 18:51
I
网红小智智 星瞳科技

按照教程操作。

https://singtown.com/learn/50240/