This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Key Press to Exit While Loop

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

Parents
  • 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?

Reply
  • 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?

Children