We'd need a lot more information to give you specifics, what exactly are you trying to do with the servos? What mcu are you using? What language are you programming in?
I've done some basic bluetooth using avr chips and webbotlib in c - my header is below, obviously yours will need to be different depending on what you're doing, note that mine calls functions to do the things I need, yours will be calling your own functions to move a leg or whatever.
I'd call initBluetooth in my main code and then process what the user types in receiveUserByte.
In my case that's move the vehicle if it's an arrow key, maybe print to an lcd, allow the user to choose a new algorithm for the vehicle and ignore certain control characters etc. It's really me just messing about trying stuff out to be honest.
If you can give us some more detail we can maybe give you something more relevant.
#ifndef bluetooth_h
#define bluetooth_h
#include "algorithms.h"
#include "printExtensions.h"
#define BLUETOOTH_UART UART0
#define BLUETOOTH_BUF_SIZE 33
// buffer to hold bluetooth input
char bluetoothBuf[BLUETOOTH_BUF_SIZE];
/**************** functions ****************/
void printAlgorithmMenu()
{
rprintf("\nChoose a new algorithm\n");
rprintf("a = Avoid Obstacles\n");
rprintf("f = Follow Object\n");
rprintf("r = Remote Control\n");
}
void receiveUserByte(unsigned char cByte)
{
static int byteNum = 0;
static boolean waitingForAlgorithmChoice = false;
if(waitingForAlgorithmChoice)
{
waitingForAlgorithmChoice = false;
switch(cByte)
{
case 'a': algorithm = avoidObstacles; rprintf("avoidObstacles!"); break;
case 'f': algorithm = followObject; rprintf("followObject!"); break;
case 'r': algorithm = remoteControl; rprintf("remoteControl!"); goNowhere(); break;
default : waitingForAlgorithmChoice = true; printAlgorithmMenu(); break;
}
}
else
{
boolean processed = true;
if(algorithm == remoteControl)
{
switch(cByte)
{
case 68 : goLeft(); rprintf("left!\n"); break;
case 67 : goRight(); rprintf("right!\n"); break;
case 66 : goBackward(); rprintf("reverse!\n"); break;
case 65 : goForward(); rprintf("go!\n"); break;
case '/': goNowhere(); rprintf("stop!\n"); break;
case '[': break;
default : processed = false;
}
}
if(algorithm != remoteControl || !processed)
{
if(cByte == 13 || byteNum == BLUETOOTH_BUF_SIZE - 2)
{
if(cByte != 13)
{
bluetoothBuf[byteNum++] = cByte;
}
bluetoothBuf[byteNum] = '\0';
displayClear(&lcd);
rrprintf(displayGetWriter(&lcd), "%s", bluetoothBuf);
byteNum = 0;
}
else if(cByte == '#')
{
printAlgorithmMenu();
waitingForAlgorithmChoice = true;
byteNum = 0;
}
else
{
if(isprint(cByte))
{
bluetoothBuf[byteNum++] = cByte;
}
}
}
}
}
void initBluetooth()
{
uartInit(BLUETOOTH_UART, 115200);
uartAttach(BLUETOOTH_UART, &receiveUserByte);
}
#endif // bluetooth_h