Hi Mike, and once again thanks for helping with this...but i must have something A**E about face here..
here is the complete code...
What happens is that when the command is read it passes to a case ZP in this example and then passes a,b,c,d to the missing variables so that softserial outputs the right code for the control..
// S120# servo 1 to position 20 degrees
#include <ctype.h>
#include <Servo.h>
#include <SoftwareSerial.h>
//softserial setup
#define rxPin 8
#define txPin 7
SoftwareSerial CAMCOM=SoftwareSerial(rxPin,txPin);
//main serial in
#define SerialSpeed 57000
#define BufferLength 16
#define LineEnd '#'
#define PinServo1 2
#define PinServo2 3
#define PinServo3 4
#define DefaultServoPosition 90
//servo setup
Servo servo1;
Servo servo2;
Servo servo3;
char inputBuffer[BufferLength];
//softserial rxtx
int zp = 0;
void setup()
{
//softserial setup
//split_digits(input_str,&a,&b,&c,&d);
pinMode(rxPin,INPUT);
pinMode(txPin,OUTPUT);
// servo pins outputs
pinMode(PinServo1, OUTPUT);
pinMode(PinServo2, OUTPUT);
pinMode(PinServo3, OUTPUT);
// attach servos and set servo-specific timing details
servo1.attach(PinServo1, 900, 2100); // Azimuth servo
servo2.attach(PinServo2, 900, 2100); // Elevation servo
servo3.attach(PinServo3, 900, 2100); // back up servo
// default servo positions
servo1.write(DefaultServoPosition);
servo2.write(DefaultServoPosition);
servo3.write(DefaultServoPosition);
Serial.begin(SerialSpeed);
CAMCOM.begin(9600);
}
// process a command string
void HandleCommand(char *input)
{
int a;
int b;
int c;
int d;
Serial.println(input);
split_digits(input,&a,&b,&c,&d);
/* now do commands based on a, b, c & d */
}
{
Serial.println(input);
if (length < 2) { // not a valid command
return;
}
int value = 0;
// calculate number following command
if (length > 2) {
value = atoi(&input[2]);
}
int* command = (int*)input;
// check commands
// note that the two bytes are swapped, ie 'RA' means command AR
switch(*command) {
case '1S':
case 'PZ':
// action ZOOM Position
CAMCOM.print(129, BYTE); // 81
CAMCOM.print(01, BYTE); // 01
CAMCOM.print(04, BYTE); // 04
CAMCOM.print(71, BYTE); // 47
CAMCOM.print(a, BYTE); // 0a
CAMCOM.print(b, BYTE); // 0b
CAMCOM.print(c, BYTE); // 0c
CAMCOM.print(d, BYTE); // 0d
CAMCOM.println(255, BYTE); // FF
// 81 04 01 47 0a 0b 0c 0d FF
Serial.println("Position");
break;
}
}
void loop()
{
// get a command string from the serial port
int inputLength = 0;
do {
while (!Serial.available()); // wait for input
inputBuffer[inputLength] = Serial.read(); // read it in
}
while (inputBuffer[inputLength] != LineEnd && ++inputLength < BufferLength);
inputBuffer[inputLength] = 0; // add null terminator
HandleCommand(inputBuffer, inputLength);
//soft serial output
int a, b, c, d;
}
the rest of the commands are simple like S1150# which is servo 1 position 150 (0-180 deg)
any of this make any sence?
thanks again.....still fighting with it...
regards,
Mike.