Skip to content

Commit

Permalink
add pwm demo and backlight setting demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed May 13, 2024
1 parent d2ad2d9 commit 0bc8505
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
26 changes: 26 additions & 0 deletions examples/peripheral/pwm/pwm_servo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from maix import pwm, time, pinmap

SERVO_PERIOD = 50 # 50Hz 20ms
SERVO_MIN_DUTY = 2.5 # 2.5% -> 0.5ms
SERVO_MAX_DUTY = 12.5 # 12.5% -> 2.5ms

# Use PWM7
pwm_id = 7
# !! set pinmap to use PWM7
pinmap.set_pin_function("A19", "PWM7")



def angle_to_duty(percent):
return (SERVO_MAX_DUTY - SERVO_MIN_DUTY) * percent / 100.0 + SERVO_MIN_DUTY


out = pwm.PWM(pwm_id, freq=SERVO_PERIOD, duty=angle_to_duty(0), enable=True)

for i in range(100):
out.duty(angle_to_duty(i))
time.sleep_ms(100)

for i in range(100):
out.duty(angle_to_duty(100 - i))
time.sleep_ms(100)
19 changes: 19 additions & 0 deletions examples/vision/display/display_backlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from maix import pwm, time, display, image

disp = display.Display()

def show(i):
img = image.Image(disp.width(), disp.height())
img.draw_circle(disp.width() // 2, disp.height() //2, 50, image.COLOR_RED, thickness=-1)
img.draw_string(2, 2, f"{i}%", image.COLOR_WHITE, scale=2)
disp.show(img)

for i in range(100):
disp.set_backlight(i)
show(i)
time.sleep_ms(50)

for i in range(100):
disp.set_backlight(100 - i)
show(100 - i)
time.sleep_ms(50)
2 changes: 1 addition & 1 deletion maix/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

version_major = 4
version_minor = 1
version_patch = 0
version_patch = 2

__version__ = "{}.{}.{}".format(version_major, version_minor, version_patch)

0 comments on commit 0bc8505

Please sign in to comment.