Embedded_game/002_B_Car/获取图片.py

58 lines
1.5 KiB
Python
Raw Normal View History

2025-01-02 12:48:11 +08:00
# Untitled - By: nian0 - 周一 11月 20 2023
import sensor, image, lcd, time
from fpioa_manager import fm
import KPU as kpu
import gc
from Maix import GPIO
from machine import Timer, PWM, UART, Timer
#初始化串口
#uart = UART(UART.UART1, 115200, read_buf_len=4096)
def Servo(angle):
'''
说明舵机控制函数
功能180度舵机angle:-90至90 表示相应的角度
360连续旋转度舵机angle:-90至90 旋转方向和速度值
duty占空比值0-100
'''
#PWM通过定时器配置接到IO17引脚
tim_pwm = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
S1 = PWM(tim_pwm, freq=50, duty=0, pin=17)
S1.duty((angle+90)/180*10+2.5)
2025-02-25 18:51:58 +08:00
# Servo(15)
2025-01-02 12:48:11 +08:00
# 摄像头初始化
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
2025-02-25 18:51:58 +08:00
sensor.skip_frames(40)
2025-01-02 12:48:11 +08:00
sensor.set_vflip(1) # 摄像头后置方式
sensor.set_pixformat(sensor.RGB565) # 设置像素格式为彩色 RGB565
#sensor.set_pixformat(sensor.GRAYSCALE) # 设置像素格式为灰色
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(0,0)
2025-02-25 18:51:58 +08:00
# lcd.init() # LCD初始化
2025-01-02 12:48:11 +08:00
# 初始化 BOOT 键
boot_pin = 16 # 根据您的板子修改对应的引脚号
fm.register(boot_pin, fm.fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_UP)
clock = time.clock()
# 拍照状态
taking_pictures = False
count = 0
while(True):
2025-02-25 18:51:58 +08:00
sensor.snapshot().save("/sd/imgs/{}.jpg".format(count))
count+=1
print(count)
time.sleep_ms(100)