Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : Cant get my processing sketch to wait for a response from the arduino

$
0
0
I personally like using the SerialCommand ( Stefan Rado / Steven Cogswell) on the Arduino side to handle the incoming Processing commands which you structure to look like <command> <data> <data>. So lets say the command is PL for plot and 1234 is the data. The string sent by Processing would be "PL 12324". On the Ardunio side you associate a callback function for PL. That function will be called when serial sees data with a first word PL. In that PL callback function you extract the 1234 and do what needs to be done. With this scheme you can add commands as you need them with a simple callback definition line. You are wide open to add features to your program. You might add "SP 10" to mean spit out 10 copies. There can be more than one argument companying the command. So you could have command string "WH 12 34 This" where WH is the command type and 12 34 This is the data. You can use a similar scheme on the Processing side where your Processing serial event code is checking all incoming serial messages for codes that represent the Arduino states. Your Processing code would not be "waiting", i.e. stopped, for the the Ardunio is ready message. It would just react appropriately when the ready message arrives. Structure the message scheme so that you can easily add message types. The Processing side might be looking for two or one characters to represent Ardunio states.  

Viewing all articles
Browse latest Browse all 1768

Trending Articles