-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCA9685Adapter.h
More file actions
36 lines (28 loc) · 1.01 KB
/
Copy pathPCA9685Adapter.h
File metadata and controls
36 lines (28 loc) · 1.01 KB
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
#ifndef PCA9685_ADAPTER_H
#define PCA9685_ADAPTER_H
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
extern bool g_pca9685MotorRampEnabled;
class PCA9685Adapter {
public:
PCA9685Adapter();
void setup(int sda, int scl, const uint8_t addr = 0x40, float pwmFrequency = 50);
void updateMotor(int channel, int8_t speedInPercent);
void stopMotorImmediate(int channel);
int currentMotorSpeed(int channel) const;
void updateServo(int channel, int16_t angle);
private:
static const int kChannelCount = 16;
static const int kMotorRampStep = 5;
static const unsigned long kMotorRampIntervalMs = 20;
Adafruit_PWMServoDriver* m_pwm = nullptr;
TwoWire m_pwmWire = TwoWire(1);
int16_t m_channels[kChannelCount];
int16_t m_motorTargets[kChannelCount];
unsigned long m_motorRampUpdateMs[kChannelCount];
bool m_isReady = false;
int16_t rampedMotorSpeed(int16_t current, int16_t target, int16_t maxStep) const;
void writeMotorOutput(int channel, int16_t speedInPercent);
};
#endif