At my school I'm doing a student electronic project which is to create a 4 x 4 LED matrix which is programmable by Arduino. I am new to Arduino so I don't know how I would create a code for a push button when pressed it will change modes until I press again, and i am using WS2812B RGB LEDs for the matrix. Is there a way to have different RGB modes in a push button? how do I create the code?
Have you worked through any of the examples in the IDE, or with the libraries?
I don't know how I would create a code for a push button when pressed it will change modes until I press again
Take a look at the StateChangeDetection example in the IDE. As written it changes between two states but can be amended to switch between several states
As to running code based on the current state, my favourite method is to use switch/case for which Mr. Google can provide lots of help
Your duplicate posts have been moved to the same forum section and merged
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a timeout from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
tinkerstudent:
At my school I'm doing a student electronic project which is to create a 4 x 4 LED matrix which is programmable by Arduino. I am new to Arduino so I don't know how I would create a code for a push button when pressed it will change modes until I press again, and i am using WS2812B RGB LEDs for the matrix. Is there a way to have different RGB modes in a push button? how do I create the code?
Look at the following tutorial as UKHeliBob suggested. StateChangeDetection
I assume if it is a school project you need to write the code yourself. It is unlikely anyone here will write the code for you. Make your best attempt and we will be glad to help.
UKHeliBob:
Take a look at the StateChangeDetection example in the IDE. As written it changes between two states but can be amended to switch between several statesAs to running code based on the current state, my favourite method is to use switch/case for which Mr. Google can provide lots of help
how would I duplicate the code so it can have different modes?
how would I duplicate the code so it can have different modes?
If you mean how do you use the SCD principle for several modes then look at what the example does. Note how the buttonPushCounter variable is incremented with each button press. Use the value of that variable to trigger a different mode for each of its values