cointaya.blogg.se

Controllermate two button one action
Controllermate two button one action









The state functions can do anything you want but must not block execution of the code, and at some time the program will need to change state. Ensure that none of the functions block the free running of the loop() function so no delay()s or while loops in the state functions, Then, in the loop() function, use a series of ifs or (my preferred method) switch/case based on the value of currentState so that the required function for the current state is called each time through loop(). Give them a number and set a variable, let's name it currentState, to the number of the current state. Let's suppose that the program is required to call function0(), function1() or function2() depending on what is required of it at the current time. I have also looked a little into the state machine concept,Īctually very easy once you stop being scared of it

#CONTROLLERMATE TWO BUTTON ONE ACTION HOW TO#

How to make all these parts work together. It sounds so simple, and I have tried many versions of button sketches, timing, and other code, but I just cant get my head around the framework. I've using the internal INPUT_PULLUP for my buttons so far. My functions are all working when run individually, so it's the button, stopping and looping part that bugs me.

controllermate two button one action controllermate two button one action controllermate two button one action

It is also critical that the function activated by the button runs until another button is pressed. It is critical that a press on a button stops the running function when pressed, and not waits for the running function to finish. If I press a certain button I want it to start doing something and stop doing what it was doing before.Įxample: I press button 1 and it starts function 1, which runs until i press button 3, which stops function 1 and starts function 3, which runs until I press button 6, which stops function 3 and starts function 6, which runs until I press another button.Īll of the buttons are momentary buttons, which are pressed and released immediately after. I’m trying to write a code that can do the following:









Controllermate two button one action