Hello! This is my first foray into LEDs so I need some assistance. I've scoured the Internet for information and I've hit a roadblock and hoping I can get some clarity. I'm making a wand prop and my goal is to have the dome at the top glow from red-->yellow-->white-->-->yellow-->red as if it's pulsing.
My Setup
I have a 12V RGB LED and I'm using an Arduino Nano. Pins D6, D10, D11 are my output to the respective MOSFETs. I'm currently doing tests with my Arduino USB to the computer. It is my understanding I should be using a buck converter for the actual project since I'll be using my 12V power supply to power my LEDs as well as my Arduino; however, the tests I am doing have the Arduino powered by USB and NOT by the 12v power supply (but the LEDs are powered by the 12V).
Initially, I tested a basic code setColor code between red, green, and blue with a delay. This worked fine so I verified that each individual pin seemed to work correctly. Then I started experimenting with different Fade codes and things went awry. I tried probably a half dozen different codes I found and the LEDs basically would just fade to random colors and would not do what I wanted. This is what I had the most success with:
int redPin = 6;
int grnPin = 10;
int bluPin =11;
void (setup){
pinMode(redPin, OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
void setRGB (int red, int green, int blue){
analogWrite (redPin, red);
analogWrite (grnPin, green);
analogWrite(bluPin, blue);
}
void loop (){
int red = 255;
int green = 0;
int blue = 0;
for (int i = 0; i <= 255; i ++){
green = i;
setRGB (red, green, blue);
delay(20);
}
for (int i = 0; i<= 255; i++){
blue = i;
setRGB(red,green,blue);
delay(20);
}
for (int i = 0; i <=255; i++){
blue = 255 - i;
setRGB(red, green, blue);
delay (20);
}
for (int i = 0; i<=255; i++){
green = 255 - i;
setRGB(red, green, blue);
delay(20);
}
}
What happens is it starts red, then passes through yellow and becomes green, then becomes blue, and then it just starts glowing randomly colors. The only thing I can think of is the for (int i) phrase is doing things to the other variables that I don't understand. I also have some digital LEDs in the mail--I'm curious if those would be easier to manage than the RGBs here.
Please help!
Thank you!

