Difference between revisions of "Realistic Fire Simulation"
| Line 32: | Line 32: | ||
} | } | ||
</pre> | </pre> | ||
| + | |||
| + | |||
| + | Demonstration: | ||
| + | |||
| + | {{#evt: | ||
| + | service=youtube | ||
| + | |id=https://youtu.be/a-6UNgORXR8 | ||
| + | |alignment=left | ||
| + | }} | ||
Revision as of 17:04, 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
}
Demonstration:


