Hey guys I am having trouble with my code. What i want to do is have a servo on a timer so say every 3 minutes it rotates and then i want an override switch. So the problem is that the servo will twitch in a back and forth motion but when the button is pressed it rotates as intended. After the button is pressed the servo continues to spin even though it is not prompted to. I think it's a problem with our code but i'm not 100% sure on anything right now
const int buttonPin = 2;
#include<Servo.h>
Servo servo1; // create servo object to control a servo
// twelve servo objects can be created on most boards
int servoRun = 1000;
int pos = 0; // variable to store the servo position
int buttonState = 0;
void setup() {
servo1.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (pos == 0)
{
delay(1000);
for (pos = 0; pos <= 360; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo1.write(pos); // tell servo to go to position in variable 'pos'
}
}
if (buttonState == HIGH)
{
for (pos = 0; pos <= 360; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo1.write(pos); // tell servo to go to position in variable 'pos'
}
}else{
pos = 0;
}
}
Forgot to post the code if it was the problem here it is
blankdot24:
the servo continues to spin
Servos don't spin, or do you mean this is a continuous rotation servo?