-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectTest.cpp
More file actions
executable file
·39 lines (33 loc) · 1021 Bytes
/
Copy pathObjectTest.cpp
File metadata and controls
executable file
·39 lines (33 loc) · 1021 Bytes
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
37
38
39
#include <unistd.h>
#include <list>
#include "AdeeptHatLib/AdeeptHat.h"
#include "AdeeptHatLib/Servo.h"
// PCA9685 I2C address (check your HAT's documentation and/or I2C scan)
const int PCA9685_ADDRESS = 0x40; // Default address, may need to be changed.
void startServos(std::list<AdeeptServo>& servos, int address) {
for (auto& servo : servos) {
servo.startup(address);
}
}
int main() {
AdeeptRobotHat hat; //creates the hat object. should only be one.
AdeeptServo servo0(hat, 0);
std::list<AdeeptServo> servos = {servo0};
usleep(20); //wait 20ms for startup
int address = hat.openI2c(PCA9685_ADDRESS);
startServos(servos, address);
int angle = 0;
//runs the servo between three angles for testing
while (true) {
if (angle == 0) {
angle = 180;
} else if (angle == 180) {
angle = 90;
} else {
angle = 0;
}
servo0.setAngle(angle);
usleep(1000000); //wait 1s
}
return 0;
}