Files
micro_mpc_kmk/servo.py
T
Artem Kashaev 34294a86e8 Add initial project files including configuration and LED control scripts
- Create .gitignore to exclude unnecessary files
- Add .micropico for project identification
- Implement config.json for switch configurations
- Develop led_panel_blink.py for LED control with color cycling
- Create main.py to manage switch commands and interactions
- Introduce servo.py for servo control functionality
- Define switch.py to handle switch operations with servo integration
2025-12-22 13:42:17 +05:00

16 lines
436 B
Python

from machine import Pin, PWM
class Servo:
def __init__(self, pin):
self.pwm = PWM(Pin(pin))
self.pwm.freq(50)
self.min_duty = 1638 # ~0.5 ms
self.max_duty = 8192 # ~2.5 ms
def angle(self, deg):
deg = max(0, min(180, deg))
duty = int(self.min_duty + (deg / 180) * (self.max_duty - self.min_duty))
self.pwm.duty_u16(duty)
def off(self):
self.pwm.duty_u16(0)