Difference between revisions of "Realistic Fire Simulation"
(Created page with "In this page is described how to create a realistic flickering fire effect with LEDs and an Arduino board. In this case I used a Digispark due to its small size. File:f...") |
|||
| Line 6: | Line 6: | ||
[[File:firesimled03.jpg]] | [[File:firesimled03.jpg]] | ||
| + | |||
| + | <pre> | ||
| + | int p1 = 0; // Set the 3 pins with PWM | ||
| + | int p2 = 1; | ||
| + | int p3 = 4; | ||
| + | |||
| + | void setup() { | ||
| + | pinMode(p1, OUTPUT); // Set the pins as output | ||
| + | pinMode(p2, OUTPUT); | ||
| + | pinMode(p3, OUTPUT); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | int v1, v2, v3; | ||
| + | |||
| + | v1 = random(155) + 100; // Calculate the new light | ||
| + | v2 = random(155) + 100; // intensity values for each LED | ||
| + | v3 = random(155) + 100; | ||
| + | |||
| + | analogWrite(p1, 255 - v1); // Apply the light intensity | ||
| + | analogWrite(p2, 255 - v2); // to each LED | ||
| + | analogWrite(p3, 255 - v3); | ||
| + | |||
| + | delay(20 + random(80)); // Wait some random time for next udpate | ||
| + | } | ||
| + | </pre> | ||
Revision as of 11:06, 4 January 2016
In this page is described how to create a realistic flickering fire effect with LEDs and an Arduino board. In this case I used a Digispark due to its small size.
int p1 = 0; // Set the 3 pins with PWM
int p2 = 1;
int p3 = 4;
void setup() {
pinMode(p1, OUTPUT); // Set the pins as output
pinMode(p2, OUTPUT);
pinMode(p3, OUTPUT);
}
void loop() {
int v1, v2, v3;
v1 = random(155) + 100; // Calculate the new light
v2 = random(155) + 100; // intensity values for each LED
v3 = random(155) + 100;
analogWrite(p1, 255 - v1); // Apply the light intensity
analogWrite(p2, 255 - v2); // to each LED
analogWrite(p3, 255 - v3);
delay(20 + random(80)); // Wait some random time for next udpate
}


