Arduino doesn't execute command from XBee

Can anyone help me to take a look of the code following? GREEN CODE works fine to have motor runs forward and backward:

#include <Servo.h>
Servo motorL;
Servo motorR;
int pos = 0;
void setup() {
motorL.attach(9);
motorR.attach(10);
Serial.begin(9600);
}

void loop() {
for(pos = 0; pos < 180; pos += 1){
move(pos, pos);
delay(80);
}
for(pos = 180; pos>=1; pos-=1){
move(pos, pos);
delay(80);
}
}

void move(int L, int R){
Serial.print(L);
Serial.print(":");
Serial.println(R);
motorL.write(L);
motorR.write(R);
}

But the following RED CODE is not moving at all. I am using XBee to send the command and I am pretty(100%) sure arduino gets the command but just no movement.

#include <Servo.h>
Servo motorL;
Servo motorR;
int pos = 0;
void setup() {
motorL.attach(9);
motorR.attach(10);
Serial.begin(9600);
}
void loop() {
while (Serial.available() < 1) { //<-----------this line sure works, not an issue.
} // Wait until a character is received
char val = Serial.read();
Serial.print(val);
Serial.print(":");
switch(val){
case 'w'://Move Forward
move(180,180);
break;
case 's'://Move Backwards
move(0,0);
break;
case 'a'://Turn Left
move(0,180);
break;
case 'd'://Turn Right
move(180,0);
break;
case 'x'://Stop
move(90,90);
break;
}
delay(80); //<-----------------no matter how many seconds, I even tried delay(1000);
}

void move(int L, int R){
Serial.print(L);
Serial.print(":");
Serial.println(R);
motorL.write(L);
motorR.write(R);
}

I have tried to use IF...ELSE instead of SWITCH...CASE or delay longer but no luck.

Please let me know if anyone know this issue or experienced same thing before? Much appreciated~

I have seen some code use move(char L, char R) instead of int. I tried, but doesn't work either.
I can get following string from terminal:
a:0:180
d:180:0
w:180:180
s:0:0
z:0:0
x:90:90
w:180:180
a:0:180
Which means it does get the command thru XBee but just not execute it, but if I insert "move(60,60);" in setup(), it does work. I don't know why it doesn't recognize "move(60,60);" which send from XBee.

hardmouse:
if I insert "move(60,60);" in setup(), it does work. I don't know why it doesn't recognize "move(60,60);" which send from XBee.

Perhaps your servos don't respond to settings at the extreme edge of movement - try putting move(60,60) in the move forward case instead of move(180,180). Alternatively, try all your move commands in the switch individually from setup, to see if they do anything.

The servo library doc says that you should call refresh every 50ms. Your sketch does not have it, not sure if this is the issue, might be worth a try though. Note that you will have to rethink your serial.read logic a bit (or put the refresh in the while loop).

The servo library doc says that you should call refresh every 50ms

There hasn't been a 'refresh' method for quite a few versions now.

What happens if you eliminate the XBee, and just the serial monitor to drive the serial line?

Your switch doesn't have a default case - may be an idea to see if non-printing characters are screwing things up.

AWOL:
There hasn't been a 'refresh' method for quite a few versions now.

D'oh! Thanks. Guess who'll be using the servo library for the first time later this week when UPS delivers his parts?

This:

while (Serial.available() < 1)

plus this:

delay(30)

equals a high possibility of no serial comms if you send more than 1 or 2 characters at a time. Neither the delay or the "< 1" are necessary. It doesn't appear to be the source of your current issue, but it IS an issue.

while (Serial.available() < 1) {}

If no characters available, do nothing.
Looks reasonable to me.

"delay (30)" isn't great, but it isn't long enough for the serial buffer to overflow either.

Doh! I saw < and thought >. My bad. I should always finish my morning coffee before posting it seems.

wildbill:
The servo library doc says that you should call refresh every 50ms. Your sketch does not have it, not sure if this is the issue, might be worth a try though. Note that you will have to rethink your serial.read logic a bit (or put the refresh in the while loop).

Tried that, too. Not working either.

AWOL:
There hasn't been a 'refresh' method for quite a few versions now.
What happens if you eliminate the XBee, and just the serial monitor to drive the serial line?
Your switch doesn't have a default case - may be an idea to see if non-printing characters are screwing things up.

Yes, it will work. Like the green code up there without XBee.

I do have default before but it doesn't matter either way.

wildbill:
Perhaps your servos don't respond to settings at the extreme edge of movement - try putting move(60,60) in the move forward case instead of move(180,180). Alternatively, try all your move commands in the switch individually from setup, to see if they do anything.

ok, works now. they were outta range and I finally narrow it down to 20~150. When you met such problems you can only keep trying to find out the range.