hi all !
I have a code that make servos go from 0 to 180 degrees but the problem that I have is that I cannot figure out how to slow down the servo,s speed... here is my code... any help would be extremely appreciated !
here is the code:
#include <Servo.h>
const byte switchPinA = 2; //active low
//const byte switchPinB = 3; //active low
const byte servoPin = 9;
Servo servo;
byte switchAstate = HIGH;
//byte switchBstate = LOW;
byte servoPos = 1;
byte posA = 1; // new
byte posB = 180; // new
void setup() {
pinMode(switchPinA, INPUT_PULLUP);
// pinMode(switchPinB, INPUT_PULLUP);
servo.attach(servoPin);
}
void loop () {
readButtons();
moveServo();
}
void readButtons() {
switchAstate = digitalRead(switchPinA);
// switchBstate = digitalRead(switchPinB);
}
void moveServo() {
if (switchAstate == LOW) {
if (servoPos == posA) { // new
servoPos = posB;
delay(2000);
}
else {
servoPos = posA;
}
switchAstate = HIGH; // new
}
// if (switchBstate == LOW) {
// servoPos = 1;
// }
servo.write(servoPos);
delay(5); // modified
}