//This Arbotix-M code will rotate 2 attached Dynamixel MX-28T motors rapidly back and forth by 90deg for 5min. Please make shure that you have the correct Dynamixel libraries for the Arbotix-M motor controller installed and set ID1/ID2 to motors1/2, repectively, before uploading this code to your Arbotix-M.

#include <ax12.h> //include the Dynamixel library. 


const int SERVO_ID = 254; //this ID adresses all connected motors.

void setup()
{
  pinMode(23, OUTPUT); //Activate output pin for triggering the beginning/end of recording. Please make sure, pin23 of the Arbotix-M is connected to the correct trigger input of the used camera(s).
  digitalWrite(23, HIGH);
  dxlInit(1000000);  //Start communication at 1mbps the motors
  Serial.begin(9600); //Start serial connection at 9600bps  
  int position = dxlGetPosition(1); //Get position of motor1
  Serial.print (position); //Print motor position to serial monitor

  //For all motors enable multi-turn-mode, set multi turn offset and resolution divider.
  int dxlMode = dxlGetMode(1); 
  if(dxlMode != MULTI_TURN_MODE)
  {
    mxSetMultiTurnMode(SERVO_ID);
  }
  mxSetMultiTurnOffset(SERVO_ID, 0);
  mxSetResolutionDivider(SERVO_ID, 1);
  
  dxlSetGoalPosition(SERVO_ID, 0); 
  
}

void loop()
{
 

  dxlSetGoalPosition(SERVO_ID, 0); //move motors to zero position.  
    delay(10000); //wait 10s
  digitalWrite(23, LOW); //Trigger recording start on LOW. This method is suitable when recording with a software (eg. Streampix 7 multi camera), that will start a continuous recording of all cameras upon triggering 1 master camera.

  Serial.begin(9600); //Start serial connection at 9600bps 


//rotate 2 attached Dynamixel MX-28T motors rapidly back and forth by 90deg for 5min:

  dxlSetGoalPosition(SERVO_ID, 512); 
  delay(30000);   
    int position = dxlGetPosition(1);
    Serial.println (position * 0.087890625);
  
  dxlSetGoalPosition(SERVO_ID, -512); 
  delay(30000);
 
    Serial.println (position * 0.087890625);
  
 dxlSetGoalPosition(SERVO_ID, 512); 
  delay(30000);   
  
    Serial.println (position * 0.087890625);
  
  dxlSetGoalPosition(SERVO_ID, -512); 
  delay(30000);
    
    Serial.println (position * 0.087890625);


 dxlSetGoalPosition(SERVO_ID, 512); 
  delay(30000);   
    
    Serial.println (position * 0.087890625);
  
  dxlSetGoalPosition(SERVO_ID, -512); 
  delay(30000);
  
    Serial.println (position * 0.087890625);
    
 dxlSetGoalPosition(SERVO_ID, 512); 
  delay(30000);   
    Serial.println (position * 0.087890625);
  
  dxlSetGoalPosition(SERVO_ID, -512); 
  delay(30000);
 
    Serial.println (position * 0.087890625);
  
 dxlSetGoalPosition(SERVO_ID, 512); 
  delay(30000);   
  
    Serial.println (position * 0.087890625);
  
  dxlSetGoalPosition(SERVO_ID, -512); 
  delay(30000);
    
    Serial.println (position * 0.087890625);         
  

  digitalWrite(23, HIGH); //Trigger end of recording on HIGH.
  Serial.println ("DONE");
   while(1) { } 


}



