mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 17:58:20 +01:00
fire animation added
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>IlluCat</title>
|
||||
<title>ESP Kit</title>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" type="image/png" href="/favicon-32x32.png">
|
||||
@@ -39,7 +39,7 @@
|
||||
data-name="pattern"
|
||||
data-topic="pixels/pattern"
|
||||
data-default="0"
|
||||
data-entries='[{"text": "None", "value": "0"}, {"text": "Rainbow", "value": "1"}, {"text": "TheaterChase", "value": "2"}, {"text": "Color Wipe", "value": "3"}, {"text": "Scanner", "value": "4"}, {"text": "Fade", "value": "5"}]'
|
||||
data-entries='[{"text": "None", "value": "0"}, {"text": "Rainbow", "value": "1"}, {"text": "TheaterChase", "value": "2"}, {"text": "Color Wipe", "value": "3"}, {"text": "Scanner", "value": "4"}, {"text": "Fade", "value": "5"}, {"text": "Fire", "value": "6"}]'
|
||||
></li>
|
||||
<li class="form-row ParamSlider"
|
||||
data-name="brightness"
|
||||
|
||||
@@ -26,7 +26,8 @@ enum pattern
|
||||
THEATER_CHASE = 2,
|
||||
COLOR_WIPE = 3,
|
||||
SCANNER = 4,
|
||||
FADE = 5
|
||||
FADE = 5,
|
||||
FIRE = 6
|
||||
};
|
||||
// Patern directions supported:
|
||||
enum direction
|
||||
@@ -62,7 +63,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)(int))
|
||||
: Adafruit_NeoPixel(pixels, pin, type)
|
||||
{
|
||||
frameBuffer = (uint8_t*)malloc(768);
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
OnComplete = callback;
|
||||
TotalSteps = numPixels();
|
||||
}
|
||||
@@ -70,7 +71,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
||||
: Adafruit_NeoPixel(pixels, pin, type)
|
||||
{
|
||||
frameBuffer = (uint8_t*)malloc(768);
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
TotalSteps = numPixels();
|
||||
}
|
||||
|
||||
@@ -81,12 +82,14 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
memcpy(frameBuffer, data, len);
|
||||
}
|
||||
|
||||
void drawFrameBuffer(int w, uint8_t *frame, int length){
|
||||
for (int i = 0; i < length; i++){
|
||||
void drawFrameBuffer(int w, uint8_t *frame, int length)
|
||||
{
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
uint8_t r = frame[i];
|
||||
uint8_t g = frame[++i];
|
||||
uint8_t b = frame[++i];
|
||||
setPixelColor(i, r ,g, b);
|
||||
uint8_t g = frame[i + 1];
|
||||
uint8_t b = frame[i + 2];
|
||||
setPixelColor(i, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +125,12 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
case FADE:
|
||||
FadeUpdate();
|
||||
break;
|
||||
case FIRE:
|
||||
Fire(50, 120);
|
||||
break;
|
||||
default:
|
||||
if(bufferSize > 0){
|
||||
if (bufferSize > 0)
|
||||
{
|
||||
drawFrameBuffer(TotalSteps, frameBuffer, bufferSize);
|
||||
}
|
||||
break;
|
||||
@@ -379,6 +386,81 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
}
|
||||
void Fire(int Cooling, int Sparking)
|
||||
{
|
||||
byte heat[numPixels()];
|
||||
int cooldown;
|
||||
|
||||
// Step 1. Cool down every cell a little
|
||||
for (int i = 0; i < numPixels(); i++)
|
||||
{
|
||||
cooldown = random(0, ((Cooling * 10) / numPixels()) + 2);
|
||||
|
||||
if (cooldown > heat[i])
|
||||
{
|
||||
heat[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
heat[i] = heat[i] - cooldown;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2. Heat from each cell drifts 'up' and diffuses a little
|
||||
for (int k = numPixels() - 1; k >= 2; k--)
|
||||
{
|
||||
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
|
||||
}
|
||||
|
||||
// Step 3. Randomly ignite new 'sparks' near the bottom
|
||||
if (random(255) < Sparking)
|
||||
{
|
||||
int y = random(7);
|
||||
heat[y] = heat[y] + random(160, 255);
|
||||
//heat[y] = random(160,255);
|
||||
}
|
||||
|
||||
// Step 4. Convert heat to LED colors
|
||||
for (int j = 0; j < numPixels(); j++)
|
||||
{
|
||||
setPixelHeatColor(j, heat[j]);
|
||||
}
|
||||
|
||||
showStrip();
|
||||
}
|
||||
|
||||
void setPixelHeatColor(int Pixel, byte temperature)
|
||||
{
|
||||
// Scale 'heat' down from 0-255 to 0-191
|
||||
byte t192 = round((temperature / 255.0) * 191);
|
||||
|
||||
// calculate ramp up from
|
||||
byte heatramp = t192 & 0x3F; // 0..63
|
||||
heatramp <<= 2; // scale up to 0..252
|
||||
|
||||
// figure out which third of the spectrum we're in:
|
||||
if (t192 > 0x80)
|
||||
{ // hottest
|
||||
setPixel(Pixel, 255, 255, heatramp);
|
||||
}
|
||||
else if (t192 > 0x40)
|
||||
{ // middle
|
||||
setPixel(Pixel, 255, heatramp, 0);
|
||||
}
|
||||
else
|
||||
{ // coolest
|
||||
setPixel(Pixel, heatramp, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void setPixel(int Pixel, byte red, byte green, byte blue)
|
||||
{
|
||||
setPixelColor(Pixel, Color(red, green, blue));
|
||||
}
|
||||
void showStrip()
|
||||
{
|
||||
show();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user