At the moment I am trying to get 2 stepper motors working as a x-axis and y-axis to move I would like to be able to press the arrow keys on the keyboard to call the appropriate function to move the motors such as up arrow to move y-axis up. I currently have a arduino uno and a cnc shield and have no problems with hooking any of the hardware up. My only problem is that I cannot seem to find anywhere that explains how to use keyboard commands to allow movement to the motors, this language is new to me but I do have some experience coding so understanding what help I get shouldn't be difficult. I'm eventually trying to get a flightstick (extreme 3d pro joystick) to move the motors that are going to control a pan tilt but I'm going one step at a time and to start id like to get keyboard commands. If anyone could explain how to make it where pressing the arrow keys calls a function I should be able to implement that into my code i just cant seem to find anywhere that explains this well.
The video above is what I'm trying to control using the arrow keys on the keyboard.
Your UNO won't receive arrow keys you type on your keyboard on the PC through the IDE Serial Monitor, those are not keys that are getting transferred.
You could use '8','6',2' and '4' from your keyboard keypad (or any standard keyboard key arrangement) to serve as requests
The Serial monitor with the IDE requires you to type return to actually send the command to the Arduino. so to TILT UP you would need to type 8 and then return. (ensure the Serial monitor is set to 115200 bauds for the code below)
void setup() {
Serial.begin(115200);
}
void loop() {
int r;
switch (r = Serial.read()) {
case -1: break; // there was nothing to read
case '2': case 31: Serial.println(F("TILT DOWN")); break;
case '4': case 28: Serial.println(F("PAN LEFT")); break;
case '6': case 29: Serial.println(F("PAN RIGHT")); break;
case '8': case 30: Serial.println(F("TILT UP")); break;
default: Serial.println((uint8_t) r); break; // ignore anything else but print the code
}
}
if you take a different Serial terminal such as CoolTerm then keys are sent as they are being typed and arrow keys are sent too (on my Mac keyboard what is sent for the arrow keys are the values 28, 29, 30 and 31)
instead of printing the message, that's where you would call the function of course