Hi Everyone,
I have been searching for this thing few days and have not found anything except using simple C such as KBHIT. For example, I'm using switch command of case: "A". In this switch case, I have a while loop of printing "YES" output. While it is printing "YES" output, I want to press a key to exit the loop and stop "YES" from printing out. Can anyone help me on this.
Thanks!
Regards, Sharril
You first have to define what "key" is.
If you have a push-button connected to a GPIO, then the logical solution is that you need to either look at the state of that GPIO pin, or have a pin-change interrupt update a flag that your main loop can then look at.
If you instead want to connect your PC to the device using a serial port and press a key on the PC keyboard, then you have to implement UART communication to receive the character.
Exactly where are you stuck?
Hi,
Thanks for the reply. I manage to find it. What I did is just use "RI". For example:
Case "A": while(!IR) { Print "YES" Delay 1 second if(IR == 1) { IR = 0; break; } } break;
This work perfectly!
RI and IR? Your keyboard broken and reversing order of characters?
That is just an example mate.
Yes, but it's a broken example.
Besides the RI/IR issue, it doesn't take care of the situation of a "key" (received character) before you enter that state, in which case you never get any "YES" message printed.
Programming is very much a question of being very careful about all the details.