Hi. Firstly, huge apologies if this is in the wrong section - I'm new to processing, and afaik this is just an issue with the script itself rather than any of the other little dos scripts or arduino code it's calling.
I'm currently working on a project for Maker Faire, building a phrenology cabinet that runs a print job. I have a processing script running from arduino which calls a simple print script command through Irfanview on a button press - open("c:/print.cmd");. The print script works perfectly from processing by itself, and the arduino script works fine independently too, but when I use it all together the print doesn't run until I close the sketch. The ellipse is just for visual testing, and it also works perfectly. As the cabinet will be used for the full day, resetting the code after every use is not viable.
Is there something stupid and blindingly obvious I'm missing in the code? (I'm really a complete beginner here, so that's a huge possibility), or is there a way to 'nest' this script within another, use an exit function to quit this script and an open function to run it again? Or any other solutions anyone might have? I've been searching, and not finding any answers..
Huge thanks.
Code:
import processing.serial.*;
Serial port;
float button = 0;
boolean buttonOn = false;
void setup()
{
size(500,500);
port = new Serial(this, Serial.list()[3], 9600);
port.bufferUntil('\n');
smooth();
}
void draw()
{
background(0);
ellipseMode(CENTER);
ellipse(250,250,250,250);
stroke(255);
fill(button*255);
}
void serialEvent (Serial port)
{
button = float(port.readStringUntil('\n'));
if(button == 1 && ! buttonOn) {
open("c:/print.cmd");
println("Someone pressed the button and I'll do something");
buttonOn = true;
}
if(button == 0 && buttonOn) {
println("Someone released the button and I'll do somethingelse");
buttonOn = false;
}
}
1