/ Ever_Burning_Flame_Painting / Ever_Burning_Flame_Painting.ino
Ever_Burning_Flame_Painting.ino
1 // SPDX-FileCopyrightText: 2018 Erin St Blaine for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include <Adafruit_CircuitPlayground.h> 6 #include <FastLED.h> // add FastLED library AFTER Circuit Playground library to avoid issues 7 8 #define STRIP1_DATA_PIN 9 // define data pins for all 3 LED strips 9 #define STRIP2_DATA_PIN 12 10 #define STRIP3_DATA_PIN 6 11 12 #define COLOR_ORDER GRB 13 14 #define NUM_LEDS 80 // how many LEDs in each strip 15 #define NUM_LEDS_2 52 16 #define NUM_LEDS_3 69 17 18 #define CAP_THRESHOLD 50 //Change capacitive touch sensitivitiy here 19 #define FRAMES_PER_SECOND 35 // faster or slower burning fire 20 21 #define COOLING 55 // Less cooling = taller flames. Default 55, suggested range 20-100 22 #define SPARKING 50 //Higher chance = more roaring fire. Default 120, suggested range 50-200 23 #define BRIGHTNESS 125 // set global brightness here. 0-255 24 #define FADE 40 //How slowly the LEDs fade to off 25 26 CRGB leds[NUM_LEDS]; //separate LED arrays for all 3 strips 27 CRGB leds2[NUM_LEDS_2]; 28 CRGB leds3[NUM_LEDS_3]; 29 30 static byte heat[NUM_LEDS]; // separate heat arrays for all 3 strips 31 static byte heat2[NUM_LEDS_2]; 32 static byte heat3[NUM_LEDS_3]; 33 34 CRGBPalette16 currentPalette; 35 TBlendType currentBlending; 36 CRGBPalette16 gPal; 37 38 39 //BUTTON SETUP STUFF 40 byte prevKeyState = HIGH; 41 42 //FIRST ACTIVE MODE 43 #define NUM_MODES 1 // actually 2 modes, mode 0 (off) and mode 1 (on) 44 int ledMode = 1; // change to 0 to make the LEDs dark on startup 45 46 //READ CAP TOUCH BUTTON STATE 47 boolean capButton(uint8_t pad) { 48 if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) { 49 return true; 50 } else { 51 return false; 52 } 53 } 54 55 //-------------------------------------------------- 56 void setup() { 57 // Initialize serial. 58 Serial.begin(9600); 59 60 // Initialize Circuit Playground library. 61 CircuitPlayground.begin(); 62 63 // Add all 3 LED strips for FastLED library 64 FastLED.addLeds<WS2812B, STRIP1_DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); 65 FastLED.addLeds<WS2812B, STRIP2_DATA_PIN, COLOR_ORDER>(leds2, NUM_LEDS_2).setCorrection( TypicalLEDStrip ); 66 FastLED.addLeds<WS2812B, STRIP3_DATA_PIN, COLOR_ORDER>(leds3, NUM_LEDS_3).setCorrection( TypicalLEDStrip ); 67 68 //Set global brightness 69 FastLED.setBrightness(BRIGHTNESS); 70 currentBlending = LINEARBLEND; 71 // Choose your color Palette 72 gPal = HeatColors_p; 73 //gpal = LavaColors_p; 74 //gpal = RainbowColors_p; 75 //gpal = CloudColors_p; 76 //gpal = ForestColors_p; 77 //gpal = PartyColors_p; 78 //gpal = RainbowStripeColors_p; 79 80 } 81 82 //----------------------------------------------------- 83 void loop() { 84 switch (ledMode) { 85 case 0: fire(); break; 86 case 1: alloff(); break; 87 } 88 // READ THE BUTTON 89 byte currKeyState = capButton(10); 90 Serial.println (capButton(10)); 91 if ((prevKeyState == true) && (currKeyState == false)) { 92 keyRelease(); 93 } 94 95 prevKeyState = currKeyState; 96 97 } 98 99 100 //BUTTON CONTROL 101 void keyRelease() { 102 Serial.println("short"); 103 104 ledMode++; 105 if (ledMode > NUM_MODES){ 106 ledMode=0; } 107 } 108 109 110 void fire() 111 { 112 113 currentPalette = HeatColors_p; 114 Fire2012WithPalette(); // run simulation frame, using palette colors 115 Fire2012WithPalette2(); 116 Fire2012WithPalette3(); 117 FastLED.show(); // display this frame 118 FastLED.delay(1000 / FRAMES_PER_SECOND); 119 120 } 121 122 123 void Fire2012WithPalette() 124 { 125 random16_add_entropy( random()); 126 127 for( int i = 0; i < NUM_LEDS; i++) { 128 heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2)); 129 } 130 for( int k= NUM_LEDS - 3; k > 0; k--) { 131 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; 132 } 133 if( random8() < SPARKING ) { 134 int y = random8(7); 135 heat[y] = qadd8( heat[y], random8(160,255) ); 136 } 137 for( int j = 0; j < NUM_LEDS; j++) { 138 byte colorindex = scale8( heat[j], 240); 139 leds[j] = ColorFromPalette( currentPalette, colorindex); 140 141 } 142 } 143 144 void Fire2012WithPalette2() 145 { 146 random16_add_entropy( random()); 147 static byte heat2[NUM_LEDS_2]; 148 for( int i = 0; i < NUM_LEDS_2; i++) { 149 heat2[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS_2) + 2)); 150 } 151 for( int k= NUM_LEDS_2 - 3; k > 0; k--) { 152 heat2[k] = (heat2[k - 1] + heat2[k - 2] + heat2[k - 2] ) / 3; 153 } 154 if( random8() < SPARKING ) { 155 int y = random8(7); 156 heat2[y] = qadd8( heat2[y], random8(160,255) ); 157 } 158 for( int j = 0; j < NUM_LEDS_2; j++) { 159 byte colorindex = scale8( heat2[j], 240); 160 leds2[j] = ColorFromPalette( currentPalette, colorindex); 161 162 } 163 } 164 void Fire2012WithPalette3() 165 { 166 random16_add_entropy( random()); 167 for( int i = 0; i < NUM_LEDS_3; i++) { 168 heat3[i] = qsub8( heat3[i], random8(0, ((COOLING * 10) / NUM_LEDS_3) + 2)); 169 } 170 for( int k= NUM_LEDS_3 - 3; k > 0; k--) { 171 heat3[k] = (heat3[k - 1] + heat3[k - 2] + heat3[k - 2] ) / 3; 172 } 173 if( random8() < SPARKING ) { 174 int y = random8(7); 175 heat3[y] = qadd8( heat3[y], random8(160,255) ); 176 } 177 for( int j = 0; j < NUM_LEDS_3; j++) { 178 byte colorindex = scale8( heat3[j], 240); 179 leds3[j] = ColorFromPalette( currentPalette, colorindex); 180 181 } 182 } 183 184 185 void alloff() { // Fade all LEDs slowly to black 186 for (int i = 0; i < NUM_LEDS; i++){ 187 leds[i].fadeToBlackBy( FADE ); 188 leds2[i].fadeToBlackBy( FADE ); 189 leds3[i].fadeToBlackBy( FADE ); 190 } 191 for(int i = 0; i < NUM_LEDS; i++) { 192 heat[i] = 0; 193 } 194 for(int i = 0; i < NUM_LEDS; i++) { 195 heat2[i] = 0; 196 } 197 for(int i = 0; i < NUM_LEDS; i++) { 198 heat3[i] = 0; 199 } 200 201 FastLED.show(); 202 delay(20); 203 }