I am working with an Arduino Uno a 16 channel pwm servo driver, and some basic servos. I am trying to get the servos to "open" (move to 180 degrees) based on a sensor input, then "close" (move back to 0 degrees) when sensor is not reading said input. How can I keep the servo at 180 degrees without automatically returning to zero? The code im working with is below.
if (sensorValue < 75 ) {
for (uint16_t angle = 0; angle < 180; angle++) {
pwm.setPWM(1, 0, map(angle, 0, 180, SERVOMIN, SERVOMAX));
delay(20);
}
}
if (sensorValue > 75 ) {
for (uint16_t angle = 180; angle > 0; angle--) {
pwm.setPWM(1, 0, map(angle, 0, 180, SERVOMIN, SERVOMAX));
delay(30);
}
}
}