Map() and RGB LED's

I am trying to make an RGB LED to fade in and out in proportion to the resistance of 3 potentiometers using the map() function. There is one potentiometer for every colour in the LED.

const int Gin = A0;   //Green sensor in
const int G = 11;     //Green LED out
int Gsensor = 0;      //Green sensor value
int Gvalue = 0;       //Green remapped value

const int Rin = A3;   //Red sensor in  
const int R = 12;     //Red LED out 
int Rsensor = 0;      //Red sensor value    
int Rvalue = 0;       //Red remapped value 

const int Bin = A2;   //Blue sensor in  
const int B = 10;     //Blue LED out
int Bsensor = 0;      //Blue sensor value
int Bvalue = 0;       //Blue remapped value

void setup() {
 pinMode(G, OUTPUT);
 pinMode(R, OUTPUT);
 pinMode(B, OUTPUT);
 
}

void loop() {

  Gsensor = analogRead(Gin);
  Gvalue = map(Gsensor, 0, 1023, 0, 255);
  analogWrite(G, Gvalue);

  Bsensor = analogRead(Bin);
  Bvalue = map(Bsensor, 0, 1023, 0, 255);
  analogWrite(B, Bvalue);

  Rsensor = analogRead(Rin);
  Rvalue = map(Rsensor, 0, 1023, 0, 255);
  analogWrite(R, Rvalue);

}

]

That is my code for it but the blue and green ones are working fine and fading in and out in proportion but the red one always seems to just turn on when it hits a certain resistance level and i cant figure out with it is doing so.

Nevermind, i just forgot that not all pins are PWM and 12 is not which i had the red led hooked up to

1 Like