|
- #if !defined( ARDUINO_ESP32C3_DEV )
- #error This code is intended to run on the ESP32_C3 platform! Please check your Tools->Board setting.
- #endif
- #define TIMER_INTERRUPT_DEBUG 1
- #define ISR_SERVO_DEBUG 1
- // Select different ESP32 timer number (0-1) to avoid conflict
- #define USE_ESP32_TIMER_NO 1
- #include "ESP32_C3_ISR_Servo.h"
- // Published values for SG90 servos; adjust if needed
- #define MIN_MICROS 544 //544
- #define MAX_MICROS 2450
- int servoIndex1 = -1;
- int servoIndex2 = -1;
- void setup()
- {
- Serial.begin(9600);
- while (!Serial);
- delay(200);
- Serial.print(F("\nStarting ISR_MultiServos on ")); Serial.println(ARDUINO_BOARD);
- Serial.println(ESP32_C3_ISR_SERVO_VERSION);
-
- //Select ESP32 timer USE_ESP32_TIMER_NO
- ESP32_ISR_Servos.useTimer(USE_ESP32_TIMER_NO);
- servoIndex1 = ESP32_ISR_Servos.setupServo(10, MIN_MICROS, MAX_MICROS);
- servoIndex2 = ESP32_ISR_Servos.setupServo(2, MIN_MICROS, MAX_MICROS);
- if (servoIndex1 != -1)
- Serial.println(F("Setup Servo1 OK"));
- else
- Serial.println(F("Setup Servo1 failed"));
- if (servoIndex2 != -1)
- Serial.println(F("Setup Servo2 OK"));
- else
- Serial.println(F("Setup Servo2 failed"));
- }
- void loop()
- {
- int position;
- if ( ( servoIndex1 != -1) && ( servoIndex2 != -1) )
- {
- for (position = 0; position <= 180; position++)
- {
- // goes from 0 degrees to 180 degrees
- // in steps of 1 degree
- if (position % 30 == 0)
- {
- Serial.print(F("Servo1 pos = ")); Serial.print(position);
- Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position);
- }
- ESP32_ISR_Servos.setPosition(servoIndex1, position);
- ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
- // waits 30ms for the servo to reach the position
- delay(30);
- }
-
- delay(5000);
- for (position = 180; position >= 0; position--)
- {
- // goes from 180 degrees to 0 degrees
- if (position % 30 == 0)
- {
- Serial.print(F("Servo1 pos = ")); Serial.print(position);
- Serial.print(F(", Servo2 pos = ")); Serial.println(180 - position);
- }
- ESP32_ISR_Servos.setPosition(servoIndex1, position);
- ESP32_ISR_Servos.setPosition(servoIndex2, 180 - position);
- // waits 30ms for the servo to reach the position
- delay(30);
- }
-
- delay(5000);
- }
- }
复制代码 |
|