Hi, I'm a beginner and I know very little about C++ language and I'd need help with this project I'm trying to make.
My aim is to learn how to control any output using the PC keyboard as a "controller".
I'm planning on buinding a robot arm and I tought about using the keyboard buttons to make the servo motors move forward or backward. For example, using the " serial.read() " function, i want the servos to react when they receive a specific keystroke, however not by typing for example "forward" in the serial monitor, despite just by holding a key on the keyboard and watching the robot arm move; for example, I hold the up arrow key on the keyboard and the arm goes forward.
Is such thing possible? Thanks in advance to anyone who will help me!
This code will read keyboard repeats from a terminal program like TeraTerm or CoolTerm via the Arduino USB Serial
// readOneChar.ino
// Reads one char cmds from Serial
// https://www.forward.com.au/pfod/ArduinoProgramming/SoftwareSolutions/index.html
// Pros: Extremely Simple, Non-blocking and Robust
// Cons: Nothing really. You can do a lot with 52 one char cmds (A..Z,a..z)
void setup() {
Serial.begin(9600);
for (int i = 10; i > 0; i--) {
Serial.print(' '); Serial.print(i);
delay(500);
}
Serial.println();
}
void loop() {
char c = Serial.read(); // note read() returns an int, char c = converts it to a char
if (c != -1) { // read() return -1 if there is nothing to be read.
// got a char handle it
Serial.println(c);
// <<< add your code to to handle 'f' for forward 'r' for reverse etc
}
}