hornedCapybara

I have a 3 x 3 led matrix with my led pins 2-10 and a button on 11, and variable resistor on Analog 0. I am trying to fit 5 programs into one, and it switches between them on a button press. this is my code so far:

There are programming errors and logic errors in your code, it won't compile and the layout does not help.First you need to fix the setup function. ledPins is an array of pin numbers so which pin will be set to OUTPUT by this statement ?

LOOPRead the current button state and remember itRead the button state again and remember it with a different nameIf the state has not changed do nothing, keep looking, go round the loop againIf it has changed (button has been pressed or released) If it has been pressed (state now HIGH) remember the new state as the old state, go round the loop againElse (we now know that it has just been released)Remember the new state as the old stateIncrement the button press counterIf the button press counter has gone beyond the maximum reset it to zeroTest the button press counterIf zero call programzero()If one call programone()If two call programtwo()etc, etcKEEP GOING ROUND THE LOOP

NOTE - there is no debouncing unless you expressly do it when reading the button

Please do not send me PMs asking for help. Post in the forum then everyone will benefit from seeing the questions and answers.

gianlucalongoni

Hi!if i got the target you're trying to reach...You want to switch among five choices, using a button.I wrote down the following sketch, providing a second pushbutton (startButton), whose aim is to start the acquisition time for data from the other switch (commandButton).In this way you tell arduino "pay attention i'm sending you the number of the program i want you to run, and i will tell you that number, by the number of clicks i will perform on the commandButton."