So I have done this simple code with continuous rotation servos
#include <Servo.h>
Servo servoLW;
void setup() {
servoLW.attach(9); // Attaches servoLW to pin 9
servoLW.write(180);
delay(3000);
servoLW.write(0);
delay(3000);
servoLW.write(90);
}
The servo does everything in the code nicely but then the servo continues to repeat the servoLW.write(180) afterwards.
What have I done wrong???
INTP
2
You mean it keeps doing full speed in the 180 direction or is it looping through the whole process?
It goes full speed in the same direction for about 3 secs, then stops for about 3 secs, and repeats that over and over.
INTP
4
Is that the entirety of your actual code?
Maybe it still needs a
void loop(){
}
even if you have nothing in it.
As for the behavior you want- spin one direction for 3 seconds, spin the other direction for 3 seconds, and THEN stop for good?
Yes thats the entire code. I thought once it ran what I wanted it to, it would just come to a stop forever.
I'm unsure of what i would put in the loop to fix this, any suggestions?
J-M-L
6
Without the loop() it crashes and restarts ..?? (Weird though).
How can the sketch compile without loop()?
INTP
8
Good question. Won't compile on my Sketch.