I’ve been trying to create a controller for my quadruped but can’t get the Servo objects from Servo.h to work inside classes.
I’ve written a very simple example to narrow down the problem. This will compile and upload but doesn’t produce any motion.
#include <Servo.h>
class Joint {
private:
Servo actuator;
public:
Joint(int);
void setAngle(float);
};
Joint::Joint(int pin) {
actuator.attach(pin);
}
void Joint::setAngle(float angle) {
Serial.print(angle);
actuator.write(angle);
}
Joint joint(36);
void setup() {
}
void loop() {
for (int angle = 45; angle < 135; angle++) {
joint.setAngle(angle);
delay(15);
}
for (int angle = 135; angle > 45; angle--) {
joint.setAngle(angle);
delay(15);
}
}
Maybe you noticed that this is just like the “Sweep” servo example with the servo inside a special class. Sweep works fine.
I would be very grateful for any help.