例程讲解05-Snapshot->time_lapse_photos延时拍照
import machine
import sensor
import os
rtc = machine.RTC()
newFile = False
try:
os.stat("time.txt")
except OSError:
rtc.datetime((2018, 3, 9, 5, 13, 0, 0, 0))
newFile = True
dateTime = rtc.datetime()
year = str(dateTime[0])
month = "%02d" % dateTime[1]
day = "%02d" % dateTime[2]
hour = "%02d" % dateTime[4]
minute = "%02d" % dateTime[5]
second = "%02d" % dateTime[6]
subSecond = str(dateTime[7])
newName = "I" + year + month + day + hour + minute + second
rtc.wakeup(10000)
BLUE_LED_PIN = 3
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time=1000)
led = machine.LED("LED_BLUE")
if newFile:
with open("time.txt", "a") as timeFile:
timeFile.write("name, year, month, day, hours, minutes, seconds, subseconds\n")
timeFile.write(
f"{newName},{year},{month},{day},{hour},{minute},{second},{subSecond}\n"
)
else:
with open("time.txt", "a") as timeFile:
timeFile.write(
f"{newName},{year},{month},{day},{hour},{minute},{second},{subSecond}\n"
)
if not "images" in os.listdir():
os.mkdir("images")
led.on()
img = sensor.snapshot()
img.save("images/" + newName, quality=90)
led.off()
machine.deepsleep()
星瞳科技OpenMV官方中文文档函数讲解: