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.
}
}
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.
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.
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