Pages: [1]   Go Down
Author Topic: My version of the flickering candle..... but without the flickering.  (Read 788 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 29
Posts: 2443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



I say real... but it's obviously not, how close to a real effect is the question
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the code ?

And a schematic ?

Logged

Offline Offline
Faraday Member
**
Karma: 65
Posts: 2500
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cjdelphi,
Are you seeking opinion?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Offline Offline
Edison Member
*
Karma: 29
Posts: 2443
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i used some other guys code and tinkered with it, using the first 5 pins, i changed the delay
and got this.... i think its very similar to a real candle flame, i need to modify it to check
to see if any of the flames are out and start them up before it gets too dark as the delay
could be short enough to become really bright and then really dark too quickly...

anyway.

Code:
// Fade all IO by Osamu Iwasaki
// November 10, 2010

#include <MsTimer2.h>

#define OUT_MIN 2  // First pin
#define OUT_MAX 9  // Last pin (this includes the analog pins)

byte luminance[20];
byte lumi[20] = {};

void setup()
{
 int i;

 for(i = OUT_MIN; i <= OUT_MAX; i++){
   pinMode(i, OUTPUT);
   digitalWrite(i,LOW);
 }


 for(i = OUT_MIN; i <= OUT_MAX; i++){
   digitalWrite(i,HIGH);
   delay(150);
 }
 for(i = OUT_MIN; i <= OUT_MAX; i++){
   digitalWrite(i,LOW);
   //delay(50);
 }
 delay(100);

 MsTimer2::set(1, int_pwm);
 MsTimer2::start();
}


void int_pwm() {

 static int f_wait[20];
 static int f_max_time[20];
 static int f_speed[20];
 static int f_ct[20];
 static long f_interval[20];

 static int ch;

 for(ch = OUT_MIN; ch <= OUT_MAX; ch++){
   if(f_wait[ch] == 0){
     f_wait[ch] = f_speed[ch] + 1;

     if( (f_ct[ch] < 255) )
       if(luminance[ch] != 255)
         luminance[ch] ++;

     if(f_ct[ch] == 255){
       if(f_max_time[ch] == 0)
         f_max_time[ch] = 0; // On Max Time
       else
         f_max_time[ch] --;
     }

     if( (f_ct[ch] > 255) && (f_ct[ch] < 511) && (f_max_time[ch] == 0))
       if(luminance[ch] != 0)
         luminance[ch] --;

     if(f_ct[ch] >= 511){
       if(f_interval[ch] == 0){
         f_interval[ch] = 200; // fading seed
         f_speed[ch] = random(100); // fading speed
         f_ct[ch] = 0;
       }
       else
         f_interval[ch] --;
     }
     else
       f_ct[ch] ++;
   }
   f_wait[ch] --;
 }
}

void fading(){

 static byte counter = 0;
 static boolean prev_off[20];
 int i;

 for(i = OUT_MIN; i <= OUT_MAX; i++){
   if(lumi[i] == 0){
     if(prev_off[i] == HIGH){
       digitalWrite(i,LOW);
       prev_off[i] = LOW;
//       delay(1);
     }
   }
   else
     lumi[i] --;
 }

 counter --;

 if(counter == 0){
   for(i = OUT_MIN ; i <= OUT_MAX; i++){
     if(luminance[i]){
       digitalWrite(i,HIGH);
       prev_off[i] = HIGH;
//       delay(30);       
     }
     lumi[i] = luminance[i];
   }
 }
}


void loop(){
 fading();
// delay(10);
}
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the code
It looks like you are using all the pins so can you drop a schematic in or a picture of the wiring?
Logged

Pages: [1]   Go Up
Jump to: