I believe this is because I am trying to turn on pins that are simultaneously being told to be turned off when not in the left or right region of the frame.
I am using pins 7, 0, 2 and 3. I use 0 and 3 when turning left, 7 and 2 when turning right and when going forward I want to use pin 7 and three, as shown below. So the problem is that I cannot enable pin 7 and 3 for going forward because, well, those pins are told to be turned off when the center of my ball is not in the left or right region.
I also tried not turning off the pins when center.x is not in their respective region, but the result of that was worse.
Is there a fix for this?
Code: Select all
if(center.x > leftBorder && center.x < rightBorder)
{
cout << "Ball is in the middle" << endl;
softPwmWrite(7,wheelspeed);
softPwmWrite(3,wheelspeed);
}
else
{
softPwmWrite(7,0);
softPwmWrite(3,0);
}
if(center.x < leftBorder)
{
cout << "Ball is to the left" << endl;
softPwmWrite(0,wheelspeed);
softPwmWrite(3,wheelspeed);
}
else
{
softPwmWrite(0,0);
softPwmWrite(3,0);
}
if(center.x > rightBorder)
{
cout << "Ball is to the right" << endl;
softPwmWrite(7,wheelspeed);
softPwmWrite(2,wheelspeed);
}
else
{
softPwmWrite(7,0);
softPwmWrite(2,0);
}