9#if defined(ARDUINO_ARCH_RP2040)
11# include "pico/stdlib.h"
12# include "hardware/pwm.h"
27 void attach(uint8_t servoPin)
30 pwmChannel = pin % 2 == 0 ? PWM_CHAN_A : PWM_CHAN_B;
31 gpio_set_function(pin, GPIO_FUNC_PWM);
32 slice_num = pwm_gpio_to_slice_num(pin);
33 pwm_set_clkdiv(slice_num, F_CPU / 1000000);
34 pwm_set_wrap(slice_num, 19999);
35 pwm_set_enabled(slice_num,
true);
37 void write(uint8_t angle)
39 writeMicroseconds(map(angle, 0, 180, 500, 2500));
41 void writeMicroseconds(
unsigned long time)
44 pwm_set_chan_level(slice_num, pwmChannel, writeTime + 1);
47 unsigned long readMicroseconds()
const
53 return map(readMicroseconds(), 500, 2500, 0, 180);