Potentiometer and LEDs

Hello!

I would like to create if potentiometer value is 0 - 341 to get green LED brightness from 0 to 255. Then if 341 - 682 to get red LED brightness from 0 - 255 and if 682 - 1023 to get yellow LED from 0 - 255.

How to do that?

Thanks! :slight_smile:

Something like...

int potVal = analogRead(potPin);

if (potVal < 342)
{
  analogWrite(greenLedPin, map(potVal, 0, 341, 0, 255));
}
else if ((potVal > 341) && (potVal < 683))
{
  analogWrite(redLedPin, map(potVal, 342, 682, 0, 255));
}
else
{
  analogWrite(yellowLedPin, map(potVal, 683, 1023, 0, 255));
}

might get you started.

Thanks!
:slight_smile: