-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighSpeedServo.ino
More file actions
42 lines (35 loc) · 1006 Bytes
/
Copy pathHighSpeedServo.ino
File metadata and controls
42 lines (35 loc) · 1006 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
40
41
42
/**
* HighSpeedServo.ino - High refresh-rate servo control (333Hz)
*
* Digital servos that support 300-400Hz PWM can respond faster than
* standard 50Hz servos while using the same pulse width protocol.
*
* Wiring: Servo signal -> GPIO 13, VCC -> 5V, GND -> GND
*/
#include <RoboServoHighSpeed.h>
RoboServo myServo;
const int SERVO_PIN = 13;
void setup() {
Serial.begin(115200);
if (roboServoAttachHighSpeed(myServo, SERVO_PIN) == ROBOSERVO_INVALID_SERVO) {
Serial.println("Failed to attach servo!");
while (1) delay(1000);
}
Serial.printf("High-speed servo attached at %d Hz\n", myServo.getFrequency());
myServo.write(90);
delay(500);
}
void loop() {
// Sweep 0° -> 180°
for (int angle = 0; angle <= 180; angle += 5) {
myServo.write(angle);
delay(15);
}
delay(300);
// Sweep 180° -> 0°
for (int angle = 180; angle >= 0; angle -= 5) {
myServo.write(angle);
delay(15);
}
delay(300);
}