58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
# 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)
|
||
|
||
# Servo(15)
|
||
# 摄像头初始化
|
||
sensor.reset()
|
||
sensor.set_pixformat(sensor.RGB565)
|
||
sensor.set_framesize(sensor.QVGA)
|
||
sensor.skip_frames(40)
|
||
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)
|
||
|
||
|
||
|
||
# lcd.init() # LCD初始化
|
||
|
||
# 初始化 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):
|
||
sensor.snapshot().save("/sd/imgs/{}.jpg".format(count))
|
||
count+=1
|
||
print(count)
|
||
time.sleep_ms(100)
|