Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- //#include <ColorConverterLib.h>
- #define NUM_LEDS 192
- #define kMatrixHeight 24
- #define kMatrixWidth 8
- #define currentBrightness 60
- CRGB Leds1[NUM_LEDS];
- CRGB Leds2[NUM_LEDS];
- CRGB leds[NUM_LEDS];
- void setup()
- {
- Serial.begin(115200);
- FastLED.addLeds<WS2812B, 2, GRB>(leds, NUM_LEDS).setDither(0);
- FastLED.setBrightness(currentBrightness);
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 8000);
- FastLED.show();
- }
- #define FIXED_FIRE2_SCALE_FOR_Y 4 // 1-11 is scale for Y axis
- int BlendAmount = 0;
- int BlendSteps = 5;
- bool Swap = false;
- bool AutoPalette = true;
- uint8_t Scale;
- uint8_t Speed;
- uint8_t PaletteIndex;
- uint8_t Speed1 = 150; // 1-252 ...why is not 255?!
- uint8_t Scale1 = 9; // 1-99 is palette and scale for X axis
- uint8_t PaletteIndex1;
- bool Loading1 = true;
- uint8_t DeltaValue1;
- uint8_t DeltaHue1;
- uint8_t Step1;
- uint8_t pcnt1;
- uint16_t ff_x1, ff_z1;
- uint8_t Speed2 = 150; // 1-252 ...why is not 255?!
- uint8_t Scale2 = 9; // 1-99 is palette and scale for X axis
- uint8_t PaletteIndex2;
- bool Loading2 = true;
- uint8_t DeltaValue2;
- uint8_t DeltaHue2;
- uint8_t Step2;
- uint8_t pcnt2;
- uint16_t ff_x2, ff_z2;
- extern const TProgmemRGBPalette16 WaterfallColors_p FL_PROGMEM = {0x000000, 0x060707, 0x101110, 0x151717, 0x1C1D22, 0x242A28, 0x363B3A, 0x313634, 0x505552, 0x6B6C70, 0x98A4A1, 0xC1C2C1, 0xCACECF, 0xCDDEDD, 0xDEDFE0, 0xB2BAB9};
- extern const TProgmemRGBPalette16 WoodFireColors_p FL_PROGMEM = {CRGB::Black, 0x330e00, 0x661c00, 0x992900, 0xcc3700, CRGB::OrangeRed, 0xff5800, 0xff6b00, 0xff7f00, 0xff9200, CRGB::Orange, 0xffaf00, 0xffb900, 0xffc300, 0xffcd00, CRGB::Gold}; //* Orange
- extern const TProgmemRGBPalette16 NormalFire_p FL_PROGMEM = {CRGB::Black, 0x330000, 0x660000, 0x990000, 0xcc0000, CRGB::Red, 0xff0c00, 0xff1800, 0xff2400, 0xff3000, 0xff3c00, 0xff4800, 0xff5400, 0xff6000, 0xff6c00, 0xff7800}; // пытаюсь сделать что-то более приличное
- extern const TProgmemRGBPalette16 Normalp FL_PROGMEM = {CRGB::Black, 0x560000, 0x6b0000, 0x820000, 0x9a0011, CRGB::FireBrick, 0xc22520, 0xd12a1c, 0xe12f17, 0xf0350f, 0xff3c00, 0xff6400, 0xff8300, 0xffa000, 0xffba00, 0xffd400}; // пытаюсь сделать что-то более приличное
- extern const TProgmemRGBPalette16 LithiumFireColors_p FL_PROGMEM = {CRGB::Black, 0x240707, 0x470e0e, 0x6b1414, 0x8e1b1b, CRGB::FireBrick, 0xc14244, 0xd16166, 0xe08187, 0xf0a0a9, CRGB::Pink, 0xff9ec0, 0xff7bb5, 0xff59a9, 0xff369e, CRGB::DeepPink}; //* Red
- extern const TProgmemRGBPalette16 SodiumFireColors_p FL_PROGMEM = {CRGB::Black, 0x332100, 0x664200, 0x996300, 0xcc8400, CRGB::Orange, 0xffaf00, 0xffb900, 0xffc300, 0xffcd00, CRGB::Gold, 0xf8cd06, 0xf0c30d, 0xe9b913, 0xe1af1a, CRGB::Goldenrod}; //* Yellow
- extern const TProgmemRGBPalette16 CopperFireColors_p FL_PROGMEM = {CRGB::Black, 0x001a00, 0x003300, 0x004d00, 0x006600, CRGB::Green, 0x239909, 0x45b313, 0x68cc1c, 0x8ae626, CRGB::GreenYellow, 0x94f530, 0x7ceb30, 0x63e131, 0x4bd731, CRGB::LimeGreen}; //* Green
- extern const TProgmemRGBPalette16 AlcoholFireColors_p FL_PROGMEM = {CRGB::Black, 0x000033, 0x000066, 0x000099, 0x0000cc, CRGB::Blue, 0x0026ff, 0x004cff, 0x0073ff, 0x0099ff, CRGB::DeepSkyBlue, 0x1bc2fe, 0x36c5fd, 0x51c8fc, 0x6ccbfb, CRGB::LightSkyBlue}; //* Blue
- extern const TProgmemRGBPalette16 RubidiumFireColors_p FL_PROGMEM = {CRGB::Black, 0x0f001a, 0x1e0034, 0x2d004e, 0x3c0068, CRGB::Indigo, CRGB::Indigo, CRGB::Indigo, CRGB::Indigo, CRGB::Indigo, CRGB::Indigo, 0x3c0084, 0x2d0086, 0x1e0087, 0x0f0089, CRGB::DarkBlue}; //* Indigo
- extern const TProgmemRGBPalette16 PotassiumFireColors_p FL_PROGMEM = {CRGB::Black, 0x0f001a, 0x1e0034, 0x2d004e, 0x3c0068, CRGB::Indigo, 0x591694, 0x682da6, 0x7643b7, 0x855ac9, CRGB::MediumPurple, 0xa95ecd, 0xbe4bbe, 0xd439b0, 0xe926a1, CRGB::DeepPink}; //* Violet
- const TProgmemRGBPalette16 *Palette[] =
- {
- &PartyColors_p,
- &OceanColors_p,
- &LavaColors_p,
- &HeatColors_p,
- &WaterfallColors_p,
- &CloudColors_p,
- &ForestColors_p,
- &RainbowColors_p,
- &RainbowStripeColors_p,
- &WoodFireColors_p,
- &NormalFire_p,
- &Normalp,
- &LithiumFireColors_p,
- &SodiumFireColors_p,
- &CopperFireColors_p,
- &AlcoholFireColors_p,
- &RubidiumFireColors_p,
- &PotassiumFireColors_p
- };
- const TProgmemRGBPalette16 *currentPalette1 = Palette[0];
- const TProgmemRGBPalette16 *currentPalette2 = Palette[0];
- // FIRE2022 CODES //
- // Modified from //
- // ============= Эффект Огонь 2021 вариант 2 с фиксированным масштабом по оси Y ===============
- // (c) SottNick
- // На основе алгоритма https://editor.soulmatelights.com/gallery/546-fire
- // by Stepko
- void ChangePalette()
- {
- Swap = !Swap;
- if (Swap)
- {
- Loading2 = true;
- }
- else
- {
- Loading1 = true;
- }
- }
- void makeFire2022(CRGB *LEDARRAY1)
- {
- if (AutoPalette)
- {
- EVERY_N_SECONDS(10)
- {
- ChangePalette();
- }
- }
- runAll(LEDARRAY1);
- }
- void runAll(CRGB *LEDARRAY20)
- {
- EVERY_N_MILLIS(10)
- {
- blend(Leds1, Leds2, LEDARRAY20, NUM_LEDS, BlendAmount);
- if (Swap)
- {
- if (BlendAmount < 255) BlendAmount+=BlendSteps; // Blend 'up' to source 2
- }
- else
- {
- if (BlendAmount > 0) BlendAmount-=BlendSteps; // Blend 'down' to source 1
- }
- }
- draw1(Leds1);
- draw2(Leds2);
- }
- void draw1(CRGB *LEDARRAY21)
- {
- if (Loading1)
- {
- random16_set_seed(8934);
- random16_add_entropy(analogRead(32));
- Scale1 = 1+random8(99);
- Speed1 = 2+random8(169);
- if (Scale1 > 100U) Scale1 = 100U;
- PaletteIndex1 = (uint8_t)(Scale1/100.0F*((sizeof(Palette)/sizeof(TProgmemRGBPalette16 *))-0.01F));
- currentPalette1 = Palette[PaletteIndex1];
- Loading1 = false;
- if (Scale1 > 100U) Scale1 = 100U;
- Step1 = map(Speed1*Speed1, 1U, 65025U, (FIXED_FIRE2_SCALE_FOR_Y-1U)/2U+1U, FIXED_FIRE2_SCALE_FOR_Y * 18U + 44);
- DeltaValue1 = 0.7 * DeltaValue1 * DeltaValue1 + 31.3;
- pcnt1 = map(Step1, 1U, 255U, 20U, 128U);
- DeltaHue1 = 0.7 * FIXED_FIRE2_SCALE_FOR_Y * FIXED_FIRE2_SCALE_FOR_Y + 31.3;
- }
- ff_x1 += Step1;
- for (byte x = 0; x < kMatrixWidth; x++)
- {
- for (byte y = 0; y < kMatrixHeight; y++)
- {
- int16_t Bri1 = inoise8(x * DeltaValue1, (y * DeltaHue1) - ff_x1, ff_z1) - (y * (255 / kMatrixHeight));
- byte Col1 = Bri1;
- if (Bri1 < 0)
- Bri1 = 0;
- if (Bri1 != 0)
- Bri1 = 256 - (Bri1 * 0.2);
- nblend(LEDARRAY21[XY(x, y)], ColorFromPalette(*currentPalette1, Col1, Bri1), pcnt1);
- }
- }
- if (!random8())
- ff_z1++;
- FastLED.show();
- }
- void draw2(CRGB *LEDARRAY22)
- {
- if (Loading2)
- {
- random16_set_seed(8934);
- random16_add_entropy(analogRead(32));
- Scale2 = 1+random8(99);
- Speed2 = 2+random8(169);
- if (Scale2 > 100U) Scale2 = 100U;
- PaletteIndex2 = (uint8_t)(Scale2/100.0F*((sizeof(Palette)/sizeof(TProgmemRGBPalette16 *))-0.01F));
- currentPalette2 = Palette[PaletteIndex2];
- Loading2 = false;
- if (Scale2 > 100U) Scale2 = 100U;
- Step2 = map(Speed2*Speed2, 1U, 65025U, (FIXED_FIRE2_SCALE_FOR_Y-1U)/2U+1U, FIXED_FIRE2_SCALE_FOR_Y * 18U + 44);
- DeltaValue2 = 0.7 * DeltaValue2 * DeltaValue2 + 31.3;
- pcnt2 = map(Step2, 1U, 255U, 20U, 128U);
- DeltaHue2 = 0.7 * FIXED_FIRE2_SCALE_FOR_Y * FIXED_FIRE2_SCALE_FOR_Y + 31.3;
- }
- ff_x2 += Step2;
- for (byte x = 0; x < kMatrixWidth; x++)
- {
- for (byte y = 0; y < kMatrixHeight; y++)
- {
- int16_t Bri2 = inoise8(x * DeltaValue2, (y * DeltaHue2) - ff_x2, ff_z2) - (y * (255 / kMatrixHeight));
- byte Col2 = Bri2;
- if (Bri2 < 0)
- Bri2 = 0;
- if (Bri2 != 0)
- Bri2 = 256 - (Bri2 * 0.2);
- nblend(LEDARRAY22[XY(x, y)], ColorFromPalette(*currentPalette2, Col2, Bri2), pcnt2);
- }
- }
- if (!random8())
- ff_z2++;
- FastLED.show();
- }
- void loop()
- {
- makeFire2022(leds);
- }
- uint16_t XY( uint8_t x, uint8_t y)
- {
- if(y >= kMatrixHeight) { y = kMatrixHeight - 1; }
- if(x >= kMatrixWidth) { x = kMatrixWidth - 1; }
- uint16_t ret;
- ret = (x * kMatrixHeight) + y;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement