Hello, i'm working on a project with servo motor's and micro switches and am having a problem with the code, here is the code (ill explain the problem shortly):
const int Lsencor = 4;
const int Rsencor = 7;
#include <Servo.h>
Servo myservo;
Servo myservo2;
int Lsencorvar = 0;
int Rsencorvar = 0;
void setup()
{
pinMode (Lsencor, INPUT);
pinMode (Rsencor, INPUT);
myservo.attach(5); //Left wheel
myservo2.attach(6); //Right wheel
}
void forward()
{
myservo.write(10);
myservo2.write(180);
}
void turnright()
{
myservo.write(92);
myservo2.write(92);
delay(250);
myservo.write(180);
myservo2.write(10);
delay(500);
myservo.write(45);
delay(500);
}
void turnleft()
{
myservo.write(92);
myservo2.write(92);
delay(250);
myservo.write(180);
myservo2.write(10);
delay(500); <--------------------------PROBLEM AREA
myservo.write(150);
delay(500);
}
void back()
{
myservo.write(180);
myservo2.write(10);
}
void loop()
{
Lsencorvar = digitalRead (Lsencor);
Rsencorvar = digitalRead (Rsencor);
if (Lsencor == HIGH)
{
turnright();
}
if (Rsencor == HIGH)
{
turnleft();
}
else
{
forward
}
}
if you saw the arrow pointing to the delay then you just looked at my problem. My problem is when i run that part of the code the board resets every time it gets to that delay. any suggestions on how to fix this? PS: feel free to point out anything else you see that might be wrong.