Zápisník experimentátora
Hierarchy: ATtiny85
Two years ago, I programmed a fire simulation for Arduino Uno. In this article, we try to do this simulation using the ATtiny85 microcontroller. To prevent the program from being exactly the same, we modify the simulation slightly to set the flashing of the flame.
I used these parts:
From the neopixel_fire01
program, I chosed only a important part. For each LED, the basic color fire_color
is set and the random color diff_color
is subtracted. This color is calculated so that the resulting color darkens most in the R
component and less in the G
and B
components. The result is a red hue of the fire, which in rare cases passes to a totally dark color.
void NeoFire::Draw()
{
Clear();
for(int i=0;i<CNT;i++)
{
AddColor(i, fire_color);
int r = random(RANDOM_MAX);
uint32_t diff_color = strip.Color ( r, r/2, r/2);
SubstractColor(i, diff_color);
}
strip.show();
}
From the neopixel_fire02
program I chosed only a important part. The potentiometer, which is connected to pin A2
, reads the analog value. It is adjusted to the appropriate range with the function map. With the potentiometer you can reach an almost invisible flame in one extreme position. In the second extreme position, flashing is extremely strong. This way you can set the flashing intensity of the entire simulation.
void NeoFire::Draw()
{
Clear();
int pot = analogRead(A2);
pot = map(pot, 0, 1023, 0, RANDOM_MAX);
for(int i=0;i<CNT;i++)
{
AddColor(i, fire_color);
int r = random(pot);
uint32_t diff_color = strip.Color (r, r/2, r/2);
SubstractColor(i, diff_color);
}
strip.show();
}
The source code is located on the GitHub server.
30.03.2018