Alternate two sets of LED's one solid and one flickering

I am looking to set some LED's so that they alternate between one set of 3 staying on for a period of time and then turning off and when this set turns off a separate set turns on and flickers for a certain amount of time and then turns off and the first set turns back on in the same fashion as before and then the cycle repeats. My code below is what I have so far and unfortunately it isnt working the way I want it to. What is happening is the LED's that are supposed to be solid turn on at the delay interval set but then the LED's that are supposed to flickering are just slowly dimming and then turn back on bright and start to dim again slowly. I am using an Arduino Uno R3 with 220Ohm resistors on the flickering set and 430Ohm on the solid set. I am not sure what I am missing but I have tried many different delay settings and get different results but not what I am looking for.

int ledFlicker;
int ledPin = 8;
int secondLedPin = 12;
int thirdLedPin = 13;
void setup()
  pinMode(ledPin, OUTPUT);
  pinMode(secondLedPin, OUTPUT);
  pinMode(thirdLedPin, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

void loop() {
  ledFlicker = random(150) + 170;
  digitalWrite(ledPin, HIGH);
  digitalWrite(secondLedPin, HIGH);
  digitalWrite(thirdLedPin, HIGH);
  digitalWrite(ledPin, LOW);
  digitalWrite(secondLedPin, LOW);
  digitalWrite(thirdLedPin, LOW);
  analogWrite(9, ledFlicker);
  analogWrite(10, ledFlicker);
  analogWrite(11, ledFlicker);

What is you understanding of what LED flickering is? What is your understanding of how you are dimming the LEDs? How is there a difference?

so when I say flickering I mean rapidly turning on and off like a strobe almost but not quite that quickly and ultimately I want it to be a random pattern that it flickers. Think of it like what you get from a fluorescent bulb when its going bad and about to burn out. As for the slowly dimming part I mean like a slow fading from fully on to off and then back to on like a breathing effect you see on a lot of RGB lighting for PC's. My goal ultimately is to use this as a lighting effect for some picture lights I have that are LED and I want to add UV led's to them so they will stay lit on the normal led bulbs for a period of time like they would be normally and then after that specified amount of time have them turn off and then have the UV LED's turn on and flicker like in a horror movie and then have it repeat as long as the lights and Arduino are on. I have some video game posters that have hidden writing on them that can only be seen with a black light and rather than having to have two separate light fixtures or having to use a UV flashlight I thought this would be a nice effect since the it fits the environment of the game they are from and it makes it more compact.

Believe it or not, but slowly fading and rapidly or slowly turning a LED on and off are all identically the same thing. What you are trying for is varying the on and off times, but you cannot get that using the Arduino "analog" pins without a lot more programing.

Got it, thats where I'm stuck I guess then I've tried them all on analog pins as well as on pwm pins and I keep getting the same result. What more would I need to do to achieve what I'm going for?

Confusing, isn't it. The analog pins are the ones that do PWM. No one admits to causing the confusion, but everyone gets caught. The only true analog pins are the ones that convert analog input voltages to a numeric value between 0 and 1023.

"The analog pins are the ones that do PWM." -> The analog pins are NOT the ones that do PWM.
On an Uno/328P, pins 3,5,6,9,10,11 are the PWM pins.
They are noted by the little ~ near the pins.
Analog inputs are made more clear, but used far less often it seems.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.