Each button is supposed to display a different output (in this case, its condensed, plum and milo).
However, if button1and button 2 is pressed one after another, I would like for it to have another output (we shall name it condensedPlum). Same case for button2 & button3 as well as button1 & button3.
This means if i were to click on button1, its output "condensed" is shown. If I were to click onto button2 next, its output "plum" is shown, and an output of "condensedPlum" is shown after.
This is the code that I have currently and I am having difficulty giving more functions to my button
Can you tell more ? When the next button is pressed, is the first button already released or are both pressed ? How much time is allowed between the buttons ?
To detect a sequence of events, you need to think in a logical way and put that in code.
Is it for school ?
For an experienced programmer, any sequence is no problem. The sequence can be put in data (in an array) or in code (with a Finite State Machine). For a beginner, you start to write down what it should do in a logical way.
Arduino has the setup() and loop() function. To keep it running smooth and responsive, the loop() has to run as often as possible, maybe hundreds or thousands times per second.
Waiting for something in a while-statement is not according to that.
All buttons pressed would be released once pressed. There isn't a specific timing between the buttons but I thought of creating a code that I could use with touchdesigner for a personal project.
I would like audience to select two buttons in total, one after each, where a output would appear in between them. And the combination of 2 different buttons would result in another different output. I'm unsure of which function or how should I group them up logically.
You could add variables to make the code easier to understand.
void loop()
{
// Part 1
// Gather all information from buttons and input.
// Put the result in variable(s).
// Part 2
// Process the information according to the variable(s).
}
If you have a global variable of the previous button, then you can check it against the current button.
For example:
// 0 = no button, 1 = condensed, 2 = plum, 3 = milo
int previousButton = 0;
The code would be easier to read:
void loop()
{
// Part 1
// Gather all information from buttons and input.
// Put the result in variable(s).
...
// Part 2
// Process the information according to the variable(s).
if (previousButton == CONDENSED and currentButton == PLUM)
{
Serial.println("Condensed-Plum");
}
}
That is just one way to do it, others write more condensed code than I do.
Are you using the Arduino IDE 2.0 ? Then please right-click in the sketch and select "Format document".