Pages: [1]   Go Down
Author Topic: Multiple Candle Flicker (up to 24 circuits)  (Read 1090 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am totally new to the Arduino and an electronics beginner.  I have a cutaway model of a sailing ship that I want to add internal illumination to.  I am looking to use 24 individual miniature LED's designed to look like candle lanterns.  I could group some of them but I would like to keep as many individual flicker circuits as possible for maximum realism.

I am currently testing individual circuits using the CDT3460 chip but I also thought there might be an Arduino solution.

There are many candle flicker sketches around but nearly all seem to be for single flames with sngle or multiple LED's.  I need many, many more individual flicker circuits.

Anyone seen anything like this?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33419
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes flickering is just like blinking. This sketch was for a small Christmas tree, change the on / off times to make it look like it is flickering.

Code:
/* Random blinking lights
for use on a christmas tree
By Mike Cook
*/

#define numberOfLights 16

byte pins[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
byte pinState[numberOfLights];
long int changeTime[numberOfLights];
int flashRate[numberOfLights];
long flashChange;   // how often to change the flashing patterns

void setup() {
  for(int i = 0; i< numberOfLights; i++) {
    pinMode(pins[i], OUTPUT);
    changeTime[i] = millis() + random(1000, 200);
    pinState[i] = LOW;
  }
  setFlashTime();
}

void loop() {
  for(int i = 0; i < numberOfLights; i++) {
   if(changeTime[i] <= millis()) {
   pinState[i] = ~pinState[i];
   digitalWrite(pins[i], pinState[i]);
   changeTime[i] = millis() + flashRate[i];
   }
  }
  if(flashChange <= millis()) setFlashTime();
}

void setFlashTime(){
  for(int i=0; i<numberOfLights; i++){
    flashRate[i] = random(200, 1500);
  }
  flashChange = millis() + 100000;  // next time to change pattern
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply, but isn't that going to look a little too "blinky"?  When I said flickering, I meant 3 or 4 pwm light levels from say 10 or 20% up to 100%.  The difficulty being not enough analog outputs.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 604
Posts: 33419
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could use several shift registers and create PWM outputs on them with this:-
http://www.elcojacobs.com/shiftpwm/
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can simulate PWM writing by simply toggling on and off at different rates. The default PWM frequency is only 490 Hz. With a 16 MHz clock you have lots of room to set up various duty cycles on various pins.

This thread here shows how I simulated PWM on all 20 pins by using an interrupt:

http://arduino.cc/forum/index.php/topic,103572.0.html
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Mike, Nick,

Thanks very much - I will be experimenting with those circuits as soon as I get some components together.
Logged

SF Bay Area
Offline Offline
Edison Member
*
Karma: 11
Posts: 1244
Arduino Ninja
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A TLC5947 is perfect for this, as it has built in 24 channel, 12-bit PWM. You can get very smooth changes in brightness, and almost imperceptible flickers if you need it. It only require any four digital pins from your Arduino.

The TLC5947 is available from many distributors as a surface mount chip. I also have a breakout board for it: http://macetech.com/store/index.php?main_page=product_info&products_id=22
Logged

Unique RGB LED Modules and Arduino shields: http://www.macetech.com/store

Pages: [1]   Go Up
Jump to: