First of all I wish everyone a great christmas and a healthy and happy new year.
I am trying to make a GUI with a “start” and “stop” button in processing with controlp5.
I want the “start” button to start my void loop on the arduino, and I want the “stop” button to stop the void loop and let the display say “done”. I tried some things and I searched a lot on the internet.
In the arduino code, I tried to make a void knop that could make sure the buttons work.
It doesn’t work and I don’t know how to make it work.
If anyone can help me with this I would be very happy.
Both arduino and processing files are as attachments.
please put your code in code tags. it's much easier for people to answer you when we don't have to download and create a new project just to take a peek at your issue.
That is not how Arduino code works. setup() gets called once and then loop() gets called repeatedly so your knop code never gets called.
You need to restructure your code. Rename your loop() function to something else and then rename your knop() function to loop(). Or, just combine the two together.
Each time through loop(), you need to see if Serial input is available. If it is, read it and act on it. If it is not, don't do anything.
Now I managed to let my previous "loop()" now called something else to start when I press the "start" button. But my "stop" button still does not what I want it to do. Here is the code of my previous "knop()" now called "loop()".
void loop() {
if (Serial.available()){
int val = Serial.read();
if(val== 1) {
shuttleruntest();
}
else if(val== 2) {
ledsAan();
display.setSegments(done);
}
}
}
Post the latest version of your code so that we can keep up.
Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask an effective question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Sometimes it helps to write a very simple sketch to see what is going on with a part of a program. So I set up my Uno with a software serial port to connect with Processing so that I could display what the Processing code sends in serial monitor.
The LED on pin 13 responds to the input from the Processing program. The Start button turns on the LED and the Stop button turns the LED off. So the Processing code and using ‘x’ for the comparison works. The issue must be in another part of your code.
display.setSegments(done);
What is that statement supposed to do? Edit: I looked at the library and understand that part now.
Please post the entire Arduino sketch. Snippets usually do not help as they leave out information and are often not the area where the real problem resides.
The for and while loops in the shuttleruntest() block execution while they run and they take a very long time to complete. The serial input is not being read while the shuttleruntest() function is running so the program cannot read serial input nor respond to the buttons.
You will need to rewrite the shuttleruntest() function so that it is non blocking. A state machine approach may be what s needed. Instead of using for and while loops, let the looping be done by the loop() function.