myservo.attach ruining everything


i'm tired of slamming head against desk.  going go gym cool down, can still check replys while im there.  in meantime, wanted see while i'm out if can give me why , not how.  can work on how fix it, don't understand why it's doing this.  here code:

code: [select]
#include "motordriver.h"
#include <servo.h>


const int buttonpin1 = 2;
int buttonstate1 = 0;
servo myservo;

void setup()
{
/*configure motor control wheel @ left side.*/
/*configure motor b control wheel @ right side.*/

        pinmode(buttonpin1, input_pullup);
        myservo.attach(7);
        motordriver.init();
motordriver.setspeed(200,motorb);
motordriver.setspeed(200,motora);
}

 
void loop()
{
buttonstate1 = digitalread(buttonpin1);
       
        if (buttonstate1 == low)
        {
       
        motordriver.goforward();
delay(2000);
motordriver.stop();
delay(1000);
motordriver.gobackward();
delay(2000);
motordriver.stop();
delay(1000);
motordriver.goleft();
delay(2000);
motordriver.stop();
delay(1000);
motordriver.goright();
delay(2000);
motordriver.stop();
delay(1000);
       
}
       



}


this going larger code.  combining servo code motor code.  have 1 motor plugged shield test, , took out servo positioning code.  when executed, motor should go forward, stop, go backwards, stop, go forward, stop, go backwards stop.  if take out
code: [select]
myservo.attach(7) push button , motor turns , celebrates.  put in myservo code anywhere in void setup, push button activates shield, indicator lights flash in order motor going 1 direction stopping , other, motor not move, or make sounds.  take out myservo code, works fine again. 

like said, can fix code how, first need understand why.  once myservo code read in arduino, stop else , focus on servo? , if so, why indicators still correspond button pushes?


my guess both libraries use timer 1.




Arduino Forum > Using Arduino > Programming Questions > myservo.attach ruining everything


arduino

Comments