Other ways to key get keyboard input while in Draw()?
in
Programming Questions
•
9 months ago
Hello all,
This is my first post, I have been scouring the forums but couldn't quite find the answer to my question, and unable to post. Firstly, my application is to use Processing with Arduino applications. Also, I don't know Java (yet). I have gotten in a bunch of trouble because I didn't fully understand the Draw loop. My goal is to make the code I write in Processing to be in the same "form" as I would write for Arduino.
For example, I currently have an Arduino that logs solar panel values and writes them to SD card. I also have this function running on Processing, writing to a files on the hard disk. Communication to the Solar Panel sensors is via Zigbee. I have while loop for doing retries if I get communication errors. I would like to quit the program in Processing by using the keyboard key "q" Thus my problem, I can't use keyPressed because the Draw loop doesn't exit. I really don't want to restructure my code because moving the code between platforms (Arduino and PC) gets messy (the code structure will be different.)
Is there a way to read the keyboard, get realtime updates from within Draw before completing Draw loop? If so, could you show me an example?
(I have investigated moving the code out of the Draw loop to a thread, and leaving the draw loop empty. I almost have that working but I have a problem opening the serial port, something about passing "this" to the thread for opening the port. I may post a question about that later :-)
I would be happy to post my code, but I am currently at work and don't have it right now. But this the basic functionality I would like
void draw () {
while (true) {
if (key = 'q') exit (); //how to read the keyboard ?
} //end while
} //end Draw
1