summaryrefslogtreecommitdiff
path: root/include/pwm.hpp
blob: 90e31cc7e84bc51d8924bbaeffed1b696571727f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "boards/pico_w.h"
#include "hardware/gpio.h"
#include "hardware/i2c.h"
#include "hardware/pwm.h"
#include "pico/stdlib.h"
#include "pico/time.h"
#include "pico/types.h"
#include "pico/divider.h"

#define SERVO_PIN 27 // Servo motor connected to GPIO PIN 32 (GP27)
#define WRAP_VALUE 65535
#define CLOCK_DIV_RATE 38.15
#define SERVO_MIN 13
#define SERVO_MAX 3
#define SERVO_RANGE -10

class PWM {
    public:
        /**
         * @brief Initialize the PWM
         * 
         */
        static void init();
        /**
         * @brief Set the duty cycle of our servo
         * 
         * @param duty_cycle_percent from 0 to 100
         */
        static void set_duty_cycle(int duty_cycle_percent);
        /**
         * @brief Set the servo percent objec to the given percent
         * 
         * @param percent from 0 to 100
         */
        static void set_servo_percent(int percent);
};