mirror of
https://github.com/openmv/openmv.git
synced 2025-09-26 23:09:13 +08:00
Merge 447e782304
into 87b01fac51
This commit is contained in:
commit
d09c6c303c
@ -1,13 +1,37 @@
|
||||
# This work is licensed under the MIT license.
|
||||
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
|
||||
# Copyright (c) 2013-2024 OpenMV LLC. All rights reserved.
|
||||
# https://github.com/openmv/openmv/blob/master/LICENSE
|
||||
#
|
||||
# This example shows off using the light shield with both the PYB and Machine Module.
|
||||
|
||||
import time
|
||||
from pyb import Pin, Timer
|
||||
|
||||
# 50kHz pin6 timer2 channel1
|
||||
light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6"))
|
||||
light.pulse_width_percent(100) # adjust light 0~100
|
||||
|
||||
while True:
|
||||
time.sleep_ms(1000)
|
||||
try:
|
||||
from pyb import Pin, Timer
|
||||
|
||||
# 50kHz pin6 timer2 channel1
|
||||
light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6"))
|
||||
|
||||
while True:
|
||||
for i in range(101):
|
||||
light.pulse_width_percent(i)
|
||||
time.sleep_ms(10)
|
||||
for i in range(101):
|
||||
light.pulse_width_percent(100 - i)
|
||||
time.sleep_ms(10)
|
||||
|
||||
|
||||
except ImportError:
|
||||
from machine import PWM, Pin
|
||||
|
||||
# 50kHz pin6 timer2 channel1
|
||||
pwm = PWM(Pin("P6"), freq=50000, duty_u16=0)
|
||||
|
||||
while True:
|
||||
for i in range(101):
|
||||
pwm.duty_u16((i * 65535) // 100)
|
||||
time.sleep_ms(10)
|
||||
for i in range(101):
|
||||
pwm.duty_u16(((100 - i) * 65535) // 100)
|
||||
time.sleep_ms(10)
|
||||
|
Loading…
Reference in New Issue
Block a user