im trying to smoothly turn an rgb led red and smoothly make it white and it doesnt work . heres the code and schem
// C++ code
//
int LRGB_RED=11;
int LRGB_GREEN=9;
int LRGB_BLUE=10;
int i=0;
void setup()
{
pinMode(LRGB_RED,OUTPUT);
pinMode(LRGB_GREEN,OUTPUT);
pinMode(LRGB_BLUE,OUTPUT);
}
void loop()
{
while(i<255) {
rgbled(i,0,0,0);
i++;
delay(100);
}
while(i>0) {
rgbled(i,0,0,0);
i=i-1;
delay(100);
}
}
void rgbled(int RED,int GREEN,int BLUE,int FADE){
digitalWrite(LRGB_RED, RED-FADE);
digitalWrite(LRGB_GREEN, GREEN-FADE);
digitalWrite(LRGB_BLUE, BLUE-FADE);
}
J-M-L
2
use three resistors, one per LED
(and look at the parameters for your call to rgbled())
You appear to be only controlling the red LED.
I'm still struggling with the concept of "smooth" and "digitalWrite"
Try this way ---->>>> rgbled(0,0,0,i);
RV mineirin
smooth isnt a part of the code
J-M-L
8
but you said
im trying to smoothly turn an rgb led red and smoothly make it white and it doesnt work
so it's part of the goal...
i mean slowly increase the brightness of red led and slowly decrasse it
J-M-L
10
if you use only the red led out of the 3, one Resistor is enough
use analogWrite() instead of digitalWrite() and of course a PWM capable pin
so i have to connect the wires to analog pins?
that worked but it instantly turns white and slowly gets red
int LRGB_RED=A0;
int LRGB_GREEN=9;
int LRGB_BLUE=10;
int i=0;
void setup()
{
pinMode(LRGB_RED,OUTPUT);
pinMode(LRGB_GREEN,OUTPUT);
pinMode(LRGB_BLUE,OUTPUT);
}
void loop()
{
while(i<255) {
rgbled(i,0,0,0);
i++;
delay(10);
}
while(i>0) {
rgbled(i,0,0,00);
i=i-1;
delay(10);
}
}
i did but it didnt work i connected them to analog pins it worked
i think thi is a math problem here that a dumb like me cant solve
while(i<255) {
rgbled(i,0,0,0);
i++;
delay(10);
}
while(i>0) {
rgbled(i,0,0,00);
i=i-1;
delay(10);
}
We can't help you solve anything if you don't post code
Hi,
In this bit of code you are digitalWrite expecting PWM.
void rgbled(int RED,int GREEN,int BLUE,int FADE){
digitalWrite(LRGB_RED, RED-FADE);
digitalWrite(LRGB_GREEN, GREEN-FADE);
digitalWrite(LRGB_BLUE, BLUE-FADE);
}
Try using analogWrite.
void rgbled(int RED,int GREEN,int BLUE,int FADE){
analogWrite(LRGB_RED, RED-FADE);
analogWrite(LRGB_GREEN, GREEN-FADE);
analogWrite(LRGB_BLUE, BLUE-FADE);
}
This may help.
When you have editred your code please post it again in a new post please.
Tom...

// C++ code
//
int LRGB_RED=A0;
int LRGB_GREEN=9;
int LRGB_BLUE=10;
int i=0;
void setup()
{
pinMode(LRGB_RED,OUTPUT);
pinMode(LRGB_GREEN,OUTPUT);
pinMode(LRGB_BLUE,OUTPUT);
}
void loop()
{
while(i<255) {
rgbled(i,0,0,0);
i++;
delay(10);
}
while(i>0) {
rgbled(i,0,0,00);
i=i-1;
delay(10);
}
}
void rgbled(int RED,int GREEN,int BLUE,int FADE){
analogWrite(LRGB_RED, RED-FADE);
digitalWrite(LRGB_GREEN, GREEN-FADE);
digitalWrite(LRGB_BLUE, BLUE-FADE);
}
Anything minus zero is . . ?
A0 is not a PWM pin.