/*
Slow Servo - Blocking and with delay
https://forum.arduino.cc/t/servo-verschiedene-positionen-mit-kurzem-halt/1281682/4
for a better variant see my homepage:
https://werner.rothschopf.net/microcontroller/202207_millis_slow_servo.htm
2024-07-15 by noiasca
to be deleted 2024-10
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// move the servo to a specified target
void move(int target, int wait = 30) {
static int current = 0; // you must remember the old position, hence the static keyword
while (target != current) {
if (target < current) {
current--;
myservo.write(current);
}
else if (target > current) {
current++;
myservo.write(current);
}
delay(wait); // dirty blocking delay
}
}
void setup() {
myservo.attach(8); // Steckplatz am Board
//Startposition 0
move (0, 0); // position, waittime
}
void loop() {
//langsam auf 100°, warten 2sek,
move(100);
delay(2000);
//langsam auf 60°, warten 2sek,
move(60);
delay (2000);
//langsam auf 180°, warten 2sek,
move (180);
delay(2000);
//zurück auf 0°
move (0, 0);
}