probably a simple solution to this

Hi there!

I'm a total newbie with programming so this might me a simple thing I haven't thought of.

For school I'm doing a little assignment which comes down to this;

I have to be able to control a RGB led with ONE potentiometer and a button.
With each button press one of the base colors needs to be selected and then with the potentiometer I have to be able to adjust the brightness. So after 3 presses you have created a color you like consisting of the 3 base colors. the fourth press of the button is a lock state. nothing happens when you turn the potentiometer.

I managed to get the code to do just that EXCEPT, when I press the button again so I can re-adjust the brightness of a base color, the color immediately takes on the value of the potentiometer. But when I want to change the second color... green in this case. Red has changed as well.

So i want to press the button but not change the color immediately, lets say I want to change the color when I adjust the potentiometer so that when I press the button twice...the red color stays the same (even though the potentiometer is not in the same position I first put it in) and on the second color (green) when I turn the potentiometer that color changes brightness.

I hope I'm being clear (Dutch, so English is not my native language). As I said I am very new to programming and have no experience whatsoever.
It feels like a simple bit of code I need but I can't figure it out. And couldn't find (or didn't know what to look for) a solution on the web.

code is written for an Arduino Uno. Code is from a larger whole. But is able to run standalone.

const int red = 9;
const int green = 10;
const int blue = 11;
const int colorMixerButton = 13;

int colorMixerButtonState = 0;
int lastColorMixerButtonState = 0;

int potMeter = A0;
int potMeterValue = 0;
int outputValue = 0;

int colorMixerCount = 0;



void colorAdjust()
{
  colorMixerButtonState = digitalRead(colorMixerButton);

  if (colorMixerButtonState != lastColorMixerButtonState)
  {
    delay(200);
    if (colorMixerButtonState == HIGH)
    {
      colorMixerCount++;
    }
  }

  if (colorMixerCount == 1)
  {
    potMeterValue = analogRead(potMeter);
    outputValue = map(potMeterValue, 0, 1023, 0, 255);
    analogWrite(red, outputValue);
    delay(2);
  }


  if (colorMixerCount == 2)
  {
    potMeterValue = analogRead(potMeter);
    outputValue = map(potMeterValue, 0, 1023, 0, 255);
    analogWrite(green, outputValue);
    delay(2);
  }

  if (colorMixerCount == 3)
  {
    potMeterValue = analogRead(potMeter);
    outputValue = map(potMeterValue, 0, 1023, 0, 255);
    analogWrite(blue, outputValue);
    delay(2);
  }

  if (colorMixerCount == 4)
  {
    colorMixerCount = 0;
    delay(100);
  }
}

void setup()
{


}

void loop()
{

  colorAdjust();

}

Hope someone is able to give me at least pointers or a bit of code to help me.

Thanks for reading!

What about if when switching from 1 colour to another, you don't consider a new potentiometer value until it is different by 'x' % when compared to a buffered value ?

Example:
pot = 45%

Buffer = 45 %

Each time you press the button, you check if : pot = buffer +- 3%. If you don't move the pot, it should be the case

If so do nothing. If not (example for red), Pot => Red

When you are happy with the new value, you can press the button and do the following : pot => buffer

That should work !

What about if when switching from 1 colour to another, you don't consider a new potentiometer value until it is different by 'x' % when compared to a buffered value ?

Example:
pot = 45%

Buffer = 45 %

Each time you press the button, you check if : pot = buffer +- 3%. If you don't move the pot, it should be the case

If so do nothing. If not (example for red), Pot => Red

When you are happy with the new value, you can press the button and do the following : pot => buffer

That should work !

Sorry for the double reply: replied using my phone and it hanged for a while...

Thought it did not make it the first time !

What if you were to wait until the pot value was at its lowest, or close to it, before applying the colour change to the selected LED ?

or

Only apply the change to the selected LED when colorMixerCount has been at its current value for say at least 1 second ? Note that you cannot use delay() for this and will need to use millis() for timing.

jasmino:
What about if when switching from 1 colour to another, you don't consider a new potentiometer value until it is different by 'x' % when compared to a buffered value ?

Example:
pot = 45%

Buffer = 45 %

Each time you press the button, you check if : pot = buffer +- 3%. If you don't move the pot, it should be the case

If so do nothing. If not (example for red), Pot => Red

When you are happy with the new value, you can press the button and do the following : pot => buffer

That should work !

Yes, this is what I had in mind! I understand what you are saying, but I have no clue whatsoever how to do it as I have not that much experience in putting down code I just don't know how to put this piece in the code I have.