How to approach

Hi. I'm working on a VU-meter using the neopixel led strip (144led/m) and want to implement some control in to it.
The idea is to use one potentiometer with momentary push button functionality to switch between "settings".

Generally it would be something like this:
At startup - Pot regulates the sensitivity of the VU-meter
After first button-push - Pot regulates the brightness of the leds
After second button-push - Pot regulates brightness of "background light" (the "non-active" leds in the vu-meter)
After third button-push - Pot regulates the color of the "background light"
And so on.

This is all in the idea-stages, so I dont have any code to post.
My problem is not knowing how to approach this.

I've allso thouht of adding LCD screen with keypad and use a menu-system to control it, but I dont want to aim to high at this moment, so that must wait until I'm a bit more used to this Arduino programming.

I really hope some of you in here have some input on the approach for this project.

And just as thats said, I just want help with the approach. I need to do the coding my self so that I get a bit more familiar with it

To calculate what press (option) you're on, I would have a variable (named something like btnCount) that would count the number of times the button is pressed, and reset back to 1 when the count hits five (always would be one more than the # of options you have).

That variable's values would then control four (or however many # of options you have) if statements which would then have code inside that would read the pot and put its value in a variable for that task. i.e. 1st option variable could be named Meter_sensitivity, 2nd could be named LED_Brightness, etc. Those variables would then control the LED's.

Hope that helps. If you have any questions feel free to ask. Also, if you need some pseudo code to go with my above explanation, I'll be glad to post it.

HailStorm:
To calculate what press (option) you're on, I would have a variable (named something like btnCount) that would count the number of times the button is pressed, and reset back to 1 when the count hits five (always would be one more than the # of options you have).

That variable's values would then control four (or however many # of options you have) if statements

or one 'switch' statement with four 'case' elements. The default 'case' (anything other than 0 - 3) resets btnCount to 0, the start state.

Thank you both. I will do some reading on both your ways to approach this and see if I understand anything of it :wink:

I have been reading and poking around with the code for a while now, but without any real progress.

Mostly I have been trying the if / else if statements, but have not aced it yet.
HailStorn, you offered to post some pseudo code to go with your explanation, and I would really like some sort of example to your method.

.:: Hoping to start understanding the coding really soon ::.

Henry_Best:
or one 'switch' statement with four 'case' elements. The default 'case' (anything other than 0 - 3) resets btnCount to 0, the start state.

If I use the switch statement, do I need to put the complete program into each case or can i put only the part of the code that change.

Lets say that I want to do something like this:
At program start the pot controls the sensitivity
After first button press the pot controls the brightness
And so on....

With the if / else if approach i used something like this
int SENSITIVITY = 0;
int BRIGHTNESS = 0;

and in the if statement i tried to map the pot to the sensitivity variable.
SENSITIVITY = map(analogRead (POTPIN), 0,1023, 0, 500;

The else if looked something like this
BRIGHTNESS = map(analogRead (POTPIN), 0, 1023, 0, 255;

The buttoncounting part of the code is working, but when i adjust the pot it changes both sensitivity and brightness.
I allso tried with some simple code that just color the neopixel strip in a color and i added int RED, int GREEN, and int BLUE but allso here it adjusted all the parameters at the same time regardless of the number of buttonpresses I have made.

To be clear i have the btnCount == 0 and 1(and 2 in the RGB test i did) in the if and else if statements.

Sorry I dont post any code. I'm currently at work and dont have the code with me.
Please dont shoot me if this has an easy answer, I'm still a noob (at best), but still reading and learning. :slight_smile:

Try something like this:

int Sensitivity = 0;
int Brightness = 0;
int state = 0;
...  //in loop()
switch (state){
case 0: Sensitivity = analogRead (POTPIN)/2;
      //do your sensitivity stuff here or call a function
     if (buttonPin ==HIGH){
         state++;
     }
     break;
case 1: Brightness = analogRead (POTPIN)/4;
  //do your brightness stuff here or call a function
      if (buttonPin ==HIGH){
         state++;
    }
     break;
..................
}

Henry_Best, you are the best. Your example showed me in the right way, and it works... ITS ALIVE!!!
Thank you so much for your help.

Now all I have to do is to implement this to my VU-Meter code instead of the test code I used when figuring this out.

Just as a small additional question.
I was thinking about adding a LCD screen to show what the pot changes.
Like I described earlier in this thread with the "at-startup", "arter first button press" etc... but all the lcd's Ive found uses ALOT of pins, and I dont think I have enouh on my UNO R3.
Is there a way to controll a LCD on less pins than the shield uses?

Yeah - there are I2C displays that only use the 2 pins for I2C, and there are SPI displays that use 4-6 pins (3 for SPI data, 1 for CS, and sometimes 1 or 2 more), and there are the Digole smart-displays that can use serial, SPI, or I2C