Thanks for the advise I manage to program the motor. But now I have a problem face which is how do program to send the comment to arduino as following:
Press down W---to enable to move forward (which I have done using switch case)
When W is press, then A is press--- to enable turning (how to do the loop inside the switch case)
You don't loop inside the switch. Instead, your loop() function should pick up new input each time, and figure out new output each time, without any waiting.
Thus, the loop() probably looks something like:
bool forward;
bool turn;
loop() {
if (Serial.available()) {
int ch = Serial.readChar(); // I forget the exact function
switch (ch) {
case 'w': forward = true;
case 's': forward = false;
case 'a': turn = true;
case 'd': turn = false;
}
}
if (forward) {
set_forward_signals();
}
else {
set_stop_signals();
}
if (turn) {
set_turn_signals();
}
else {
set_straight_signals();
}
}
Note that the set_ functions will be called all the time (each time through loop()) with the state of the controller. This is OK; setting forward when you're already moving forward should just keep moving forward. If that's not the case in your hardware (special hardware) then you have to also remember the "current" state in addition to the "desired" state, and only send a change when the desired state changes.
Please post the error message. Then read the error message. Then, assuming that's the actual code you're trying to compile, the error message should actually tell you what's wrong