I do not understand what is the role of the arduino here. Would it do something else beside returning those values?
- I recommend you move all your logic to Processing. It simplifies your program by allowing it to run without depending on an arduino unit. This makes it easier to debug and even to reproduce by community members here.
- You are using your arduino as a worker meaning you are giving it a task to complete and report back. If you need an arduino in your use case, use it as a slave then. For example, if you need to use an arduino to control an external process using IO logic, then command your arduino to do something from Processing. Processing would be doing all the logic calculation and commands the arduino whenever it is required.
- Do not use delay() inside your draw loop as this is blocking draw. Using your “flag” approach is the way to go here. Make sure you name the flag something meaningful as flag is a generic term.
- I would also drop the text file in your code. You can manage the data in memory and set the initial values in
setup(). From what I understand, you are only reading the first line of the text file.
Kf