#include <Arduino.h>
#include <ESP32Servo.h>
Servo frontLeftServo;
Servo frontRightServo;
Servo backLeftServo;
Servo backRightServo;
const int frontLeftPin = 23;
const int frontRightPin = 2;
const int backLeftPin = 22;
const int backRightPin = 15;
void moveLegForward(Servo &servo, int angle) {
servo.write(angle);
delay(150);
}
void moveLegBackward(Servo &servo, int angle) {
servo.write(angle);
delay(200);
}
void walk() {
int forwardAngle = 45;
int backwardAngle = 90;
moveLegForward(frontLeftServo, forwardAngle);
moveLegBackward(frontLeftServo, backwardAngle);
moveLegForward(frontRightServo, forwardAngle);
moveLegBackward(frontRightServo, backwardAngle);
moveLegForward(backLeftServo, forwardAngle);
moveLegBackward(backLeftServo, backwardAngle);
moveLegForward(backRightServo, forwardAngle);
moveLegBackward(backRightServo, backwardAngle);
}
void setup() {
frontLeftServo.attach(frontLeftPin);
frontRightServo.attach(frontRightPin);
backLeftServo.attach(backLeftPin);
backRightServo.attach(backRightPin);
}
void loop() {
walk();
}