madhephaestus / ESP32Servo

Arduino-compatible servo library for the ESP32
140 stars 55 forks source link

Always returning 1 as channel number #41

Closed ArJay60 closed 1 year ago

ArJay60 commented 1 year ago

Hi,

I am using following code to attach 4 servos. I want to get back the channel number used by the attach command, but this is always 1. Why can't I get the channel number after the call to attach?

define PIN_TURNOUT_0 16 // PWM Turnout 0

define PIN_TURNOUT_1 17 // PWM Turnout 1

define PIN_TURNOUT_2 18 // PWM Turnout 2

define PIN_TURNOUT_3 19 // PWM Turnout 3

sg90_0.setPeriodHertz(50); // PWM frequency for SG90 #0 sg90_1.setPeriodHertz(50); // PWM frequency for SG90 #1 sg90_2.setPeriodHertz(50); // PWM frequency for SG90 #0 sg90_3.setPeriodHertz(50); // PWM frequency for SG90 #1 int SG0 = sg90_0.attach(PIN_TURNOUT_0, 500, 2400); // Minimum and maximum pulse width (in µs) to go from 0° to 180 Serial.printf("Channel for Servo %d \n", SG0); int SG1 = sg90_1.attach(PIN_TURNOUT_1, 500, 2400); // Minimum and maximum pulse width (in µs) to go from 0° to 180 Serial.printf("Channel for Servo %d \n", SG1); int SG2 = sg90_2.attach(PIN_TURNOUT_2, 500, 2400); // Minimum and maximum pulse width (in µs) to go from 0° to 180 Serial.printf("Channel for Servo %d \n", SG2); int SG3 = sg90_3.attach(PIN_TURNOUT_3, 500, 2400); // Minimum and maximum pulse width (in µs) to go from 0° to 180 Serial.printf("Channel for Servo %d \n", SG3);

Output : Channel for Servo 1 Channel for Servo 1 Channel for Servo 1 Channel for Servo 1