i have a example ,,
// SERIAL INPUT R= ROLL T =TROTTLE P =PITCH A =AUX Y =YAW
// INPUT WIL BE LIKE THIS TRUE SERIAL ,,
// R100T200P200A0Y1024 AND
#include <Servo.h>
typedef enum { NONE, GOT_T, GOT_Y, GOT_P, GOT_R,GOT_A} states;
states state = NONE;
unsigned int currentValue;
int trot =0;
int yaw =0;
int pitch =0;
int roll =0;
int aux =0;
int servo =0;
Servo myservo;
void setup ()
{
Serial.begin (115200);
state = NONE;
myservo.attach(7);
myservo.write(0);
} // end of setup
void processT (const unsigned int value)
{
trot =value;
} // end of processTHROTTLE
void processY (const unsigned int value)
{
// do something with YAW
Serial.print ("YAW =");
Serial.println (value);
yaw =value;
} // end of processYAW
void processP (const unsigned int value)
{
// do something with PITCH
Serial.print ("PITCH = ");
Serial.println (value);
pitch =value;
} // end of processPITCH
void processR (const unsigned int value)
{
// do something with ROLL
Serial.print ("ROLL = ");
Serial.println (value);
roll =value;
} // end of processROLL
void processA (const unsigned int value)
{
// do something with AUX
Serial.print ("AUX = ");
Serial.println (value);
aux =value;
} // end of processAUX
void handlePreviousState ()
{
switch (state)
{
case GOT_T:
processT (currentValue);
break;
case GOT_Y:
processY (currentValue);
Serial.println ("PPM YAW OUT");
Serial.println (yaw);
delay (100);
break;
case GOT_P:
processP (currentValue);
Serial.println ("PPM PITCH OUT");
Serial.println (pitch);
delay (100);
break;
case GOT_R:
processR (currentValue);
Serial.println ("PPM ROLL OUT");
Serial.println (roll);
delay (100);
break;
case GOT_A:
processA (currentValue);
Serial.println ("PPM AUX OUT");
Serial.println (aux);
delay (100);
break;
} // end of switch
currentValue = 0;
} // end of handlePreviousState
void processIncomingByte (const byte c)
{
if (isdigit (c))
{
currentValue *= 10;
currentValue += c - '0';
} // end of digit
else
{
// The end of the number signals a state change
handlePreviousState ();
// set the new state, if we recognize it
switch (c)
{
case 'Y':
state = GOT_Y;
break;
case 'P':
state = GOT_P;
break;
case 'T':
state = GOT_T;
Serial.println ("WHAHAHAHAHAH");
break;
case 'R':
state = GOT_R;
break;
case 'A':
state = GOT_A;
break;
default:
state = NONE;
break;
} // end of switch on incoming byte
} // end of not digit
} // end of processIncomingByte
void loop ()
{
if (Serial.available ())
processIncomingByte (Serial.read ());
delay (1);
myservo.write(trot);
// do other stuff in loop as required
} // end of loop