Ok I'm stupid when it comes to coding. I have a simple project that I need some help with. Is it possible to make neopixle change what animation runs via multiple switches. Example they stay off till switch is flipped then if a different switch is flipped they run a different animation and vice versa.
1 Answers
Yes absolutely it is possible. As a beginner, I suggest something like this:

simulate this circuit – Schematic created using CircuitLab
In your setup you will need to declare D4 - D7 as inputs. I have used D4 - D7 but you can choose whatever pins are available.
Then in the loop part of the code you want to look for the rising edge on the input (ie when the switch is pressed). Switch debounce is less important for this application as it is not a counter but rather a mode change.
I have written a good answer for detecting a button press here.
Nick Gammon has an excellent switch tutorial gammon.com.au/switches that covers all kinds of conceivable situations (high or low, GND or +5V, internal pull-up or pull-down, capacitor debounce or software debounce, etc.)
I would imagine the code would look something like this:
if( digitalRead(SW1) == HIGH )
mode = 1;
if( digitalRead(SW2) == HIGH )
mode = 2;
if( digitalRead(SW3) == HIGH )
mode = 3;
if( digitalRead(SW4) == HIGH )
mode = 4;
You could then use a switch-case statement to run the various NeoPixel patterns.
For more programming reference see: https://www.arduino.cc/reference/en/
- 3,218
- 2
- 23
- 51