-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalibration.html
More file actions
73 lines (58 loc) · 1.86 KB
/
Copy pathcalibration.html
File metadata and controls
73 lines (58 loc) · 1.86 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Typical min and max pulse lengths. Adjust if needed.
#define SERVO_MIN 150
#define SERVO_MAX 600
int selectedPin = 0;
int currentAngle = 90;
void setup() {
Serial.begin(115200);
pwm.begin();
pwm.setPWMFreq(50); // 50 Hz for analog servos
delay(10);
Serial.println("Servo Calibration Ready.");
Serial.println("Commands:");
Serial.println(" p <pin> : Select servo channel (0-15)");
Serial.println(" a <angle> : Move to angle (0-180)");
Serial.println(" + / - : Increase or decrease angle by 5");
}
int angleToPWM(int angle) {
angle = constrain(angle, 0, 180);
return map(angle, 0, 180, SERVO_MIN, SERVO_MAX);
}
void loop() {
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.startsWith("p ")) {
selectedPin = input.substring(2).toInt();
Serial.print("Selected pin: ");
Serial.println(selectedPin);
}
else if (input.startsWith("a ")) {
currentAngle = input.substring(2).toInt();
currentAngle = constrain(currentAngle, 0, 180);
pwm.setPWM(selectedPin, 0, angleToPWM(currentAngle));
Serial.print("Moved to angle: ");
Serial.println(currentAngle);
}
else if (input == "+") {
currentAngle += 5;
currentAngle = constrain(currentAngle, 0, 180);
pwm.setPWM(selectedPin, 0, angleToPWM(currentAngle));
Serial.print("Angle increased to: ");
Serial.println(currentAngle);
}
else if (input == "-") {
currentAngle -= 5;
currentAngle = constrain(currentAngle, 0, 180);
pwm.setPWM(selectedPin, 0, angleToPWM(currentAngle));
Serial.print("Angle decreased to: ");
Serial.println(currentAngle);
}
else {
Serial.println("Unknown command.");
}
}
}