newsoftserial - having a problem sending hex

Hello,

I can't seem to have newsoftserial print the correct byte to a pololu micro maestro 6 channel.

I have this function:

void setServoTarget(int servo, int pos){
  byte byteCommand[3];
  byteCommand[0] = 0xff;
  byteCommand[1] = (servo & 0x7F);
  byteCommand[2] = (pos & 0x7F);
  for (int i = 0; i < 3; i++) controller.print(byteCommand[i]);
}

These calls to that function all work except the last one (sending a value of 254):

  setServoTarget(1,1);
  delay((500));
  setServoTarget(1,127);
  delay(500);
  setServoTarget(1,254); // also tried 200, 250

Also note that this code works:

  controller.print(0xff, BYTE);
  controller.print(0x01, BYTE);
  controller.print(0xfe, BYTE);

I'm still new to Arduino so I might be missing something, anyone have any ideas?

Instead of: void setServoTarget(int servo, int pos){

Try: void setServoTarget(int servo, byte pos){

I think it's a unsigned byte Vs a signed int problem.

Lefty

try setServoTarget(1,(byte)254); // casting to (unsigned) byte

Awesome!

Changed "int pos" to "byte pos", and then changed the byteCommand[2] to "byteCommand[2] = pos;" and it works now.