servo motor without header file to run ? and how to smooth run the servo motor?
const int led = 8;
int ledState = LOW;
unsigned long previousMillis = 0;
const long intervel = 1000;
#define left 9
#define right 10
int pos = 0;
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
Serial.print(" current=");
Serial.print(currentMillis);
Serial.print(" previous=");
Serial.print(previousMillis);
Serial.print(" previous=");
Serial.println(previousMillis);
if (currentMillis - previousMillis >= intervel) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
Serial.println(" loop");
} else {
ledState = LOW;
}
digitalWrite(led, ledState);
Serial.print("led=");
Serial.println(led);
for (pos = 0; pos <= 180; pos += 1) {
analogWrite(left, pos);
}
for (pos = 180; pos >= 0; pos -= 1) {
analogWrite(left, pos);
}
for (pos = 0; pos <= 180; pos += 1) {
analogWrite(right, pos);
}
for (pos = 180; pos >= 0; pos -= 1) {
analogWrite(right, pos);
}
}
}
