//-------------------------------------------------------------- //-- Generate a simple sequence of two position for the 4 servos //-- The two positions are simetric (pos1 = -pos1) //-------------------------------------------------------------- //-- (c) Juan Gonzalez-Gomez (Obijuan), Dec 2011 //-- GPL license //-------------------------------------------------------------- #include //-- Mapping between the servo name (in the skymega board) and the //-- arduino pins const int SERVO2 = 8; const int SERVO4 = 9; const int SERVO6 = 10; const int SERVO8 = 11; //-- Array for accesing the 4 servos Servo myservo[4]; void setup() { //-- Attaching the 4 servos myservo[0].attach(SERVO2); myservo[1].attach(SERVO4); myservo[2].attach(SERVO6); myservo[3].attach(SERVO8); } //-- Positions for the 4 servos //-- Then angle 0 correspond to the home state int pos[4] = {45,-45,45,-45}; void loop() { for (int i=0; i<4; i++) { //-- Position the servo i. Our 0 degrees correspondo to //-- 90 degrees in the arduino servo library myservo[i].write(pos[i]+90); //-- Change the position sign pos[i]*=-1; } //-- Wait delay(2000); }