So, I have a bit of an interesting project I'm tackling. I'm still relatively new to Arduino and picking it up as I go along. I am working on an old cityscape painting that previously had christmas lights installed behind it (to light up the towers, etc). However, instead of the christmas lights I want to replace them with 5mm pirahna LEDs and an Arduino to control them. There are:
19 amber LEDs: These will be on all the time
13 green LEDs: These will be on all the time
10 blue LEDs: Each of these need to go on randomly at different intervals, and I'd like them to "twinkle"
And on top of all that, I'd like to add a simple on/off switch on the back and a thumbwheel to control brightness.
I've got the LEDs and appropriate resistors and the thumbwheel (still looking for the right on/off switch), I just need some help with the actual programming: the Uno has 6 PWM outputs so I was thinking that I'd put 2 blue LEDs on each output (and 1 on it's own), and then all I need to do is figure out a function to randomize when each output is on and how to accomplish the "twinkle effect". Do you think a flicker effect like the many "candle" examples out there would accomplish the same thing? Or would a twinkle be more like a series of bright, quick flashes? Is there a way to randomize the LEDs so that they sometimes coincide (instead of just having one set on at a random interval)? I think the dimmer thumbwheel would just be as simple as setting a brightness variable that takes the pot as an input, and then that variable would control the maximum brightness of the LEDs (and twinkle effect). Could I wire the amber and green ones to a single output and still control the brightness, or would they need to be on a PWM output to accomplish that as well?
Any help or code snippets you could offer would be greatly appreciated. I'll post my progress as I work through it.
This is an example "flicker" that I found here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1192693288
Maybe I could modify this to have a longer "off duration"? Thoughts?
/*
* randomly flickering LEDs
*/
int ledPin[] = {
5, 6, 9, 10, 11}; // pwm pins only
int ledState[5]; // last state of each led
long randNumber;
void setup() {
for (int i=0; i<=4; i++){ // set each led pin as an output
pinMode(ledPin[i], OUTPUT);
}
randomSeed(analogRead(0)); // seed the rnd generator with noise from unused pin
for (int i=0; i<=4; i++){ // init each led with a random value
ledState[i] = random(20, 201);
}
}
void loop(){
for (int i=0; i<=4; i++){ // for each led:
analogWrite(ledPin[i], ledState[i]); // set the pwm value of that pin determined previously
randNumber = random(-40, 41); // generate new random number and add that to the current value
ledState[i] += randNumber; // that range can be tweaked to change the intensity of the flickering
if (ledState[i] > 200) { // clamp the limits of the pwm values so it remains within
ledState[i] = 200; // a pleasing range as well as the pwm range
}
if (ledState[i] < 10) {
ledState[i] = 10;
}
}
delay(100); // the delay between changes
}