I am working on a project for my boat. I have created multiple led speaker rings and am trying to code my arduino to control them. Specifically, I am wanting to wire a pot on the input side of a selector switch so that i can control multiple settings for my led strips. I was thinking that If i did it this way then i could feed the selector switch outputs it into the 6 analog inputs and code it to where it would read and map the pot to control different aspects of the light strips. For example, position 1 would be color hue, position 2 would be blink rate, position 3 would be brightness and so on. I am completely clueless on where I would even begin to make this happen in a manner to where once I switch positions it would maintain the last reading from the open connections to allow switching back and forth to adjust. Any help would be great!
Strip model - SK6812 (Similar WS2812B) RGBW
rings are all in parallel. 25 leds in each.
No base code yet as I am still unsure as to if this will work and how to go about doing it
Wire the selector switch to 6 digital inputs and its common terminal to GND. Use INPUT_PULLUP in the pinMode for the pins.
Read the 6 inputs to determine which one is currently LOW and use switch/case based on the selected input to run the required code to read the pot connected to an analogue input and change the parameters you require.
There will need to be some finesse in the code to prevent a parameter being changed when the pot position is read immediately after the switch position changed but you could deal with that by only reacting to the pot once it has been put near the previous position for the newly selected switch position.
Thank you. I was looking at doing something similar but wiring the pot into an analog input instead of in series with the selector switch. Additionally, would coding it to pick up on the change in position relative to its starting point when selected be a better route? And if so, how difficult would it be to define a min and maximum value for doing so? ie if color value is 200 when the selector switch is rotated and pot value is already low, turning pot up will still be limited to 255 even though the measured change would be larger than required?
Thanks again for help
My advice would be to put the input pins in an array and iterate through them to determine which is selected. You can then use the array index to refer to other values related to that selection, such as the currently set pot value.
Whilst you cannot limit the actual value returned by analogRead() you can convert it to another range using the map() function. If you want different limits and ranges for each selection you could store them in arrays indexed by the selected switch number. Using switch/case you can run completely different code for each switch position anyway so you could hard code the limits and ranges if you want to.