Can anybody tell me why my servo sweep function does not work? Its meant to be a simple mod of the generic servo sweep using millis();
Not shown--
In both the setup and loop:
currentMillis = millis();
and at the beginning of the sketch:
#include <PWMServo.h>
PWMServo myservo;
int previousMillisServo = 0;
int pos = 0;
long servoInterval = 15;
unsigned long currentMillis = 0;
So, the issue is with how I am writing the function.
Please weigh in.
Thank you!!
Not shown--
In both the setup and loop:
currentMillis = millis();
and at the beginning of the sketch:
#include <PWMServo.h>
PWMServo myservo;
int previousMillisServo = 0;
int pos = 0;
long servoInterval = 15;
unsigned long currentMillis = 0;
So, the issue is with how I am writing the function.
Please weigh in.
Thank you!!
HTML:
void servoSweep() {
if (currentMillis - previousMillisServo > servoInterval) {
previousMillisServo = currentMillis;
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
//delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
//delay(15); // waits 15ms for the servo to reach the position
}
}
}