Hi everyone, first time posting here. I'm a total newb at programming as well. Is it possible to turn on different combinations of outputs and have them stay on with momentary switches on the inputs? For example, say sw. 1 turns on outputs 1, 2 and 3. Then when sw. 2 is pressed it turns off output 1, leaves on outputs 2, 3 and turns on output 4. Will the programming be complicated if it is possible? Thanks
Is it possible to turn on different combinations of outputs and have them stay on
Yes, it is.
Will the programming be complicated if it is possible?
Not for me. Might be for you. If you have to ask the question, I'd say it's because you have little understanding of the Arduino. So, it's going to be difficult for you.
The digitalWrite function turns a pin on or off. The digitalRead function reads a switch state.
Determining what to do in response to a change in the switch state is the hard part. Only you can do that, though, since you are the only one that knows what the requirements are (what to turn on and what to turn off).
Keep in mind that buttons bounce, so you need to ignore changes to state that occur very close together.
If you are interested in responding to both button press and button release events, you'll need to keep track of the state of the button(s), or use the Button library.
Yes, I know it will be difficult for me. I was thinking it would be relatively easy for someone who has experience writing code. I have no interest in keeping track of button release events. All I am trying to do is activate an assigned number of outputs (and only those outputs) with a single button push. When a different button is pushed, only the outputs that have been assigned to that button will be active. Does that make sense?
Work out the logic with pencil and paper (flow chart, etc.) before you try to code it. That way you don't get tangled up in code syntax while trying to figure out what it is you are trying to say (in code).
Oh - when you get to the hardware part, look up "debouncing" for the switches - a potential gotcha.
There are examples that come with the Arduino software. One of them shows how to wire up and read the state of a switch. In that example, the LED lights up when the button is pressed and goes off when the button is released. Simply remove the code to turn the LED off when the button is released. Add additional digitalWrite statements to turn additional pins on.
Reading a second button is just like reading the first button. The action when the second button is pressed will be different, but it's really just a matter of passing the correct pin number and state to digitalWrite.