Arduino as ssc servo controller.

Hi, i’m using arduino as a servo controler, with the library servo.h > http://www.arduino.cc/playground/ComponentLib/Servo

And the code of this page: (i use almost the same but simpled, without some options that i don’t use)

#include <Servo.h>

Servo servo1; Servo servo2;

void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(14);
  servo1.setMaximumPulse(2200);
  servo2.attach(15);
  Serial.begin(19200);
  Serial.print("Ready");

}

void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
    }
  }

  Servo::refresh();

}

A ssc servo controller uses this 3 serial bytes:

Byte 1 Byte 2 Byte 3
[sync marker (255)] [servo # (0-254) [position (0-254)]

How can it be done? i’m newbie in programming, and i think that it will be usefull because there are a lot of generic software to control the mini ssc…

I’m planning to do a robot arm like Lynxmotion arm, but with my own design… i want to sensorize it and make it independent from pc with arduino board…

Thanks

Nobody knows about it? is only to separate the ch variable in 3 bytes, but i don't know how...

Thanks

Does this fragment help?

 void processRequest(char servo, char position) {
     // tell the given servo to go to the given position
     // your servo code here   
 }

void loop() 
{  
  if ( Serial.available()) {
    char ch = Serial.read();
    if(ch == 255){  // handle request only after getting a sync byte
        char servo, position;
        servo = Serial.read();
        position = Serial.read();
        processRequest(servo, position);        
    }   
  } 
}