What function could I use to interrupt a loop with a key I chose?
I set up a robotic arm and with some physical buttons, it moves through the X and Y coordinates (that works with a loop). What I want to do now, is to interrup that loop, and be allowed to input some X and Y coordinates myself for the arm to move, and I have no idea how to interrupt this loop.
I have found this function online "GetAsyncKeyState" (for c++), but I cannot get it to work (as I believe its library is from Windows, which does not work with arduino).
Could anyone help me please?
digitalRead() ? If the key is connected to the Arduino.
Serial.read() ? If you're referring to a key on a pc keyboard.
1. Do you want to enter the x-y value from a 4x4 Keypad connected with the Arduino UNO?
2. Do you want to enter the x-y value from the keyboard of your PC via the Serial Monitor of the IDE of Arduino UNO?
The proyect is now working, thanks. I had tought that the function 'Serial.read' would stop the loop until I wrote something. I searched on the internet and found the next code:
while (Serial.available()>0){
number = (Serial.read()-'0');
Serial.print(number);
}
This code let me enter a number without stopping the loop.
In response to GolamMostafa, what I wanted to do was enter the x-y value from a keypad and from the keyboard simultaneously.
This allows you to handle a single digit 0 -9. If you desire to enter a value of 23.57 for the x-axis and a value of 12.75 for the y-axis, you may be required to give a little bit thought on the data transmission, reception , and decoding scheme. In such case, the information of this link could be helpful.