   togle_servo[1]=mcbus->getEventVar(msg,TOGLE_SERVO_VAR + 1);
 }
 
-//the the flags var and initialize them
+/* the the flags var and initialize them */
 void initializeFlags(){
     byte flag = cbus.getNodeVar(SERVO_FLAGS_VAR);
     start_action = flag && 0x03; //first 2 bits    

        lastPos = servo_start;
      }
    }
    //write last pos to eprom
   //variables start with number 1  
    cbus.setInternalNodeVariable(servoidx+1,lastPos);

    servos[servoidx].write(lastPos,SPEED);
    //servos already attached
    //if (!attach_servo){
	servos[servoidx].attach(servopins[servoidx]);
    //}
    servos[servoidx].write(lastPos,SPEED);
   
  
}

//create the objects for each servo
void setupServos(){
  
  for (uint8_t i=0;i<NUM_SERVOS;i++){     

#include <EEPROM.h> //required by the library
#include <VarSpeedServo.h>

/* uncomment this line to see debug messages */
//#define DEBUGNODE

/* Module definitions */

#define NUM_SERVOS 13      //number of servos

/* first 2 are to indicate which servo is on. 2 bytes to indicate to togle. 2 for start and end angle */

#define VAR_PER_SERVO 6  //variables per servo
#define SPEED 50        //servo speed
#define SERVO_START 15        //servo start angle.start at 15 to avoid jitter
#define SERVO_END 180        //servo end angle


/* CBUS definitions */
#define GREEN_LED A0                  //merg green led port
#define YELLOW_LED 0                 //merg yellow led port
#define PUSH_BUTTON 9                //std merg push button

/* 
 * Node definition
 * number o node variables
 */
 
#define NODE_VARS 2 

/*                 
* var1 = Servo speed
* var2 = flags
* flag1 (2 first bits) action to take on starting. see setupServos
* flag2 (bit 3), indicate to maintain the servo attached after moving. default is 0 = detached
*/

#define SERVO_SPEED_VAR  1
#define SERVO_FLAGS_VAR  2 

#define NODE_EVENTS 30              //max number of events
#define EVENTS_VARS VAR_PER_SERVO   //number of variables per event
#define DEVICE_NUMBERS NUM_SERVOS   //number of device numbers. each servo can be a device

/* 
 * the indexes start at 1 not at 0  
 */
 
#define ACTIVE_SERVO_VAR 1          //2 bytes for that
#define TOGLE_SERVO_VAR  3          //2 bytes for that
#define START_ANGLE_VAR  5          //var index for the start angle
#define END_ANGLE_VAR    6          //var index for the end angle


/* create the merg object */
MergCBUS cbus=MergCBUS(NODE_VARS,NODE_EVENTS,EVENTS_VARS,DEVICE_NUMBERS);

/* servo controler */
VarSpeedServo servos[NUM_SERVOS];

 /* 
 * pins where the servos are attached
 * pins 9,10 and 15 don't work for many servos. servo library limitation 
 */
byte servopins[]={2,3,4,5,6,7,8,1,A1,A2,A3,A4,A5};//,19,20,21,22,23,24,25,26,27,28,29,30};
byte active_servo[2]; //store the active servo event var
byte togle_servo[2]; //store the togle servo event var
boolean attach_servo = false;
