Fixed previous error,
Now I'm having issue with interrupts.
I need to interrupt my servo when the button is LOW, I don't want to post my whole code, but unsure on what is needed and not, for the interrupt.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int buttonPin = 3;
int pos = 0; // variable to store the servo position
volatile int state = HIGH;
void setup()
{
pinMode (buttonPin, INPUT);
attachInterrupt(0, stop, LOW);
Serial.begin(9600);
myservo.attach(2); // attaches the servo on pin 9 to the servo object
}
void loop()
{
while (digitalRead(buttonPin) == HIGH)
{
for (pos = 0; pos < 180; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
Serial.println(pos);
}
for (pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
Serial.println(pos); // waits 15ms for the servo to reach the position
}
digitalRead(state);
}
}
void stop()
{
state = !state;
}