controlling an array of 10 servos


hello all,

i want control array of 10 servo motors.i using arduino mega 2560 r3 , accessing 1 servo @ particular moment

code: [select]
#include <servo.h>
 
servo absrv[10]={};  // create servo object control servo
servo myserv;                // twelve servo objects can created on boards
 
//int pos = 0;    // variable store servo position
 
void setup()
{
 serial.begin(9600);
 absrv[0].attach(22);
absrv[1].attach(23);
absrv[2].attach(24);
absrv[3].attach(25);
absrv[4].attach(26);
absrv[5].attach(27);
absrv[6].attach(28);
absrv[7].attach(29);
absrv[8].attach(30);
absrv[9].attach(31);
 // attaches servo on pin 9 servo object
//myserv.attach(31);
}
 
 void sweep(int pos,servo lserv)
{
  int i;
 for(i = 0; <= pos; += 1) // goes 0 degrees 180 degrees
  {                                  // in steps of 1 degree
    lserv.write(i);              // tell servo go position in variable 'pos'
    delay(15);                       // waits 15ms servo reach position
  }
}
 
 
void loop()
{
  int i;
  for(i=0;i<10;i++)
  {
    delay(1000);
    serial.println(i);
    if(!absrv[i].attached())
    {
      serial.print("error");
      myserv.write(60);
    }
   sweep(120,absrv[i]);
   delay(1000);
  }
 // myserv.write(60);
}




it works when number of servos less or equal 6

can try changing line
code: [select]

servo absrv[10]={};  // create servo object control servo

to
code: [select]

servo absrv[]={22,23,24,25,26,27,28,29,30,31};  // create servo object control servo


Arduino Forum > Topics > Robotics (Moderator: fabioc84) > controlling an array of 10 servos


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

sd card Could not find FAT16/FAT32 partition [solved]

Arduino Uno + KTY81/210 temperature sensor