// 500 to 2400
const int servoPin1 = 19;
const int servoPin2 = 18;
const int servoPin3 = 21;
int pulse ; // Default pulse duration (in microseconds)
int prevpulse ;
int prevmillis ;
int currentmillis ;
void setup() {
Serial.begin(9600);
pinMode(servoPin1, OUTPUT);
pinMode(servoPin2, OUTPUT);
pinMode(servoPin3, OUTPUT);
}
void loop() {
prevmillis = millis();
pulse = Serial.parseInt(); //it takes 1 second to take input
if(pulse == 0){
pulse = prevpulse;
}
do{
// Generate the PWM signal for the servo
digitalWrite(servoPin1, HIGH);
digitalWrite(servoPin2, HIGH);
digitalWrite(servoPin3, HIGH);
delayMicroseconds(pulse);
digitalWrite(servoPin1, LOW);
digitalWrite(servoPin2, LOW);
digitalWrite(servoPin3, LOW);
// Serial.println(0);
delayMicroseconds(20000 - pulse); // 20ms - duration of the pulse (50Hz)
prevpulse = pulse ;
currentmillis = millis() - prevmillis ;
}while(currentmillis < 3000);
}
//2225
//385