123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #include <ESP32Servo.h>
- Servo servo1;
- Servo servo2;
- Servo servo3;
- Servo servo4;
- Servo servo5;
- int minUs = 1000;
- int maxUs = 2000;
- int servo1Pin = 15;
- int servo2Pin = 16;
- int servo3Pin = 14;
- int servo4Pin = 32;
- int servo5Pin = 4;
- int pos = 0;
- ESP32PWM pwm;
- void setup() {
-
- ESP32PWM::allocateTimer(0);
- ESP32PWM::allocateTimer(1);
- ESP32PWM::allocateTimer(2);
- ESP32PWM::allocateTimer(3);
- Serial.begin(115200);
- servo1.setPeriodHertz(50);
- servo2.setPeriodHertz(50);
- servo3.setPeriodHertz(330);
- servo4.setPeriodHertz(200);
-
- }
- void loop() {
- servo1.attach(servo1Pin, minUs, maxUs);
- servo2.attach(servo2Pin, minUs, maxUs);
- pwm.attachPin(27, 10000);
- servo3.attach(servo3Pin, minUs, maxUs);
- servo4.attach(servo4Pin, minUs, maxUs);
-
- for (pos = 0; pos <= 180; pos += 1) {
-
- servo1.write(pos);
- delay(1);
- }
- for (pos = 180; pos >= 0; pos -= 1) {
- servo1.write(pos);
- delay(1);
- }
- for (pos = 0; pos <= 180; pos += 1) {
-
- servo2.write(pos);
- delay(1);
- }
- for (pos = 180; pos >= 0; pos -= 1) {
- servo2.write(pos);
- delay(1);
- }
- for (pos = 0; pos <= 180; pos += 1) {
-
- servo3.write(pos);
- delay(1);
- }
- for (pos = 180; pos >= 0; pos -= 1) {
- servo3.write(pos);
- delay(1);
- }
- for (pos = 0; pos <= 180; pos += 1) {
-
- servo4.write(pos);
- delay(1);
- }
- for (pos = 180; pos >= 0; pos -= 1) {
- servo4.write(pos);
- delay(1);
- }
- for (pos = 0; pos <= 180; pos += 1) {
-
- servo5.write(pos);
- delay(1);
- }
- for (pos = 180; pos >= 0; pos -= 1) {
- servo5.write(pos);
- delay(1);
- }
- servo1.detach();
- servo2.detach();;
- servo3.detach();
- servo4.detach();
- pwm.detachPin(27);
- delay(5000);
- }
|