ATtiny85 - Simulation of the fire using NeoPixel Ring

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.

Used parts

I used these parts:

  • ATtiny85 (link) - I used my board with SMD components.
  • NeoPixel Ring 24 LED (link) - Includes 24 RGB LEDs with WS2812B chip.
  • Resistor 1k (link) - The resistor is attached to the NeoPixel Ring data input. It serves as a pin protection.
  • Capacitor 220 uF (link) - The capacitor is connected between VCC and GND on NeoPixel Ringu. It is used to straighten the voltage peaks.
  • Potentiometer 10k (link) - It is used to adjust the color deviation from the base color of the fire. I've used a trimmer because it does not harm the breadboard.
  • Arduino Pro Mini (link) - It is used to program ATtiny85. You can find the programming description here.
  • SMD 8 LED board (link) - It is used to indicate logical states on the pins of the microcontroller.

The original sketch

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();
}

The sketch with potentiometer

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();
}

Video

Source code

The source code is located on the GitHub server.



Video


30.03.2018


Menu