What am I doing wrong??

Hi, I want to change the intensity of 3 LED( Green, Red, Blue). I have written a code that uses a function, but I gt seem to get it to work.
Any help would be greatly appreciated.

int intensityPotmeter (int g, int r, int b);


int potIn[3] = {6, 7, 8};      //Potmeter analog input selection.
int ledPin[3] = {2, 3, 4};    //LED digital pin selection.
int potVal = 0;               //Potmeter initial value at 0.


void setup() 
{
  pinMode(2, OUTPUT);        //Output LED pin.
  pinMode(3, OUTPUT);        //Output LED pin.
  pinMode(4, OUTPUT);        //Output LED pin.
}


void loop()
{
  
  g = intensityPotmeter() 
  r = intensityPotmeter()
  b = intensityPotmeter()

  
}
   

void intensityPotmeter()                //Intensity function.
{
  potVal = analogRead(potIn[3]);        //Define potValue as analogRead.
        //Brightness adjustment.
  for (int brightness = potVal; brightness <= 255; brightness ++) 
  {
    analogWrite (ledPin[3], brightness);    //Value of bightness.
  }
}

potVal = analogRead(potIn[3]);the fourth element of a three element array?
Hmmm.

 g = intensityPotmeter()

"Work" usually implies "it compiles, uploads, but doesn't do what I want."
This code falls at the first hurdle.

Pins 6,7,8 are not normally analog input pins.

This makes no sense at all.

int intensityPotmeter (int g, int r, int b);

Mark

hi,

note that you pmw output pins go from 0 -> 255, but you analog input pins from 0 ->1023. this means you have to use the map function to map the input to the output

it is also a good idea to use a constraint function around the map function just to make sure that the values always stay within the 0 -> 255 boundaries.

I based on the link above I have dimmed a RGB LED successfully.

I've no idea which Arduino you have but I don't think 2,3,4 are PWM.

Mark

Very important detail.
I am using a Arduino UNO.

Use 3 pots if you want to make RGB independant

int Rval = 0;
int Gval = 0;
int Bval = 0;

int Rled = 6; // Digi Pin 6
int Gled = 5; // Digi Pin 5
int Bled = 3; // Digi Pin 3

int pot = 0;

void setup()
{
  pinMode(Bled, OUTPUT);
  pinMode(Rled, OUTPUT);
  pinMode(Gled, OUTPUT);
}

void loop()
{
  pot = abs(analogRead(0) / 4);
  Rval = pot;
  Gval = pot;
  Bval = pot;
  analogWrite(Rled, Rval);
  analogWrite(Gled, Gval);
  analogWrite(Bled, Bval);
}

Use 3 pots if you want to make RGB independant

But that code just adjusts the brightness of a white LED from the RGB LED.
There is no need to set a pin to be an output if you are using a PWM value on it.

There is no need to set a pin to be an output if you are using a PWM value on it.

...or call "abs" on the result of a division of a positive integer

party poopers, jeez

yes one pot mixing 3 colours, 3 pots could be assigned one to each colour, my understanding of ABS is it allows you to steer away from an obsticle without locking the wheels

now im going to break the pic micro's back out of retirement

Thanks guys.
I'm new to Arduino, so this clarified allot for me.
:slight_smile: