Need a help with RGB-diod and a variable resistor

Hi everyone, I’m having a problem :frowning:
I wanted to build a circuit in which RGB-diod would change its colors as I change the voltage by variable resistor, but apparently diod changes through 2 basic colors and not three (red, blue and green) as I planned.

Here is my code:

int potPin = A2;
int ledPin = 9&10&11;
int val = 0;
int brightness = 255;
int fadeAmount = 3;

int leds[3] = {9, 10, 11};

int curPin[2] = {0, 1};

void setup()
{
for(int i = 0; i < 3; i++)
pinMode(leds*, OUTPUT);*

  • pinMode(ledPin, OUTPUT);*
    }
    *void loop() *
    {

  • analogWrite(leds[curPin[0]], brightness); *

  • analogWrite(leds[curPin[1]], 255 - brightness);*

  • val = analogRead(potPin); *

  • val /= 4;*

  • analogWrite(ledPin, val);*

  • brightness = val;*

  • } *
    Looks like color from pin 11 is not “in the game”.
    Thanks)

Please read How to use the forum. Especially the part abut code tags. Italic code is the hardest code...

int ledPin = 9&10&11;

Nope nope nope. Do you know what this makes?

int ledPin = 11;

You can't make up syntax. You have to go and read and learn how it is supposed to be. The compiler only takes it one way, his way.

int curPin[2] = {0, 1};
 analogWrite(leds[curPin[0]], brightness);   
   analogWrite(leds[curPin[1]], 255 - brightness);

WTF? You need an array to index with 0 and 1 to get a 0 and 1?

You're only analogWriting to two of your pins. SO it should be no wonder that only two pins are doing anything.

Delta_G:

int ledPin = 9&10&11;

Nope nope nope. Do you know what this makes?

int ledPin = 11;

I think you meant "int ledPin = 8;" . 9==B1001. 10==B1010. 11==B1011.
B1001 & B1010 => B1000. B1000 & B1011 => B1000 == 8.

johnwasser:
I think you meant "int ledPin = 8;" . 9==B1001. 10==B1010. 11==B1011.
B1001 & B1010 => B1000. B1000 & B1011 => B1000 == 8.

You're right, I did OR instead of AND. Point remains that it doesn't make any sense at all.

const byte  potPin = A2;
const byte RedLedPin = 9;
const byte GreenLedPin = 10;
const byte BlueLedPin = 11;


void setup ()
{
  pinMode(RedLedPin, OUTPUT);
  pinMode(GreenLedPin, OUTPUT);
  pinMode(BlueLedPin, OUTPUT);
}


void loop()
{
  int hue = analogRead(potPin);  // A hue value from 0 to 1023
  
  int hextant = (hue * 6) / 1024;  // Divide the range int 6 parts; (0-5)
  
  int fade = (6 * hue) % 1024; // How far into the part we are (0-1023)
  fade /= 4;  // 0-255


  // Convert Hue to RGB
  int Red, Green, Blue;
  switch (hextant)
  {
    case 0:  Red = 255;
      Green = fade;  // Fade from Red to Yellow
      Blue = 0;
      break;


    case 1:  Red = 255 - fade; // Fade from Yellow to Green
      Green = 255;
      Blue = 0;
      break;


    case 2:  Red = 0;
      Green = 255;
      Blue = fade;  // Fade from Green to Cyan
      break;


    case 3:  Red = 0;
      Green = 255 - fade; // Fade from Cyan to Blue
      Blue = 255;
      break;


    case 4:  Red = fade;  // Fade from Blue to Magenta
      Green = 0;
      Blue = 255;
      break;


    case 5:  Red = 255;  // Fade from Magenta to Red
      Green = 0;
      Blue = 255 - fade;
      break;
  }
  analogWrite(RedLedPin, Red);
  analogWrite(GreenLedPin, Green);
  analogWrite(BlueLedPin, Blue);
}