Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <FastLED.h>
- #include <JC_Button.h>
- #define COLOR_ORDER GRB
- #define CHIPSET WS2812
- #define SABER_NUM_LEDS 45
- #define SABER_PIN 18
- #define SABER_COLOR 0x44b0db // use RGB (hex) color picker
- #define SABER_SPEED 8 //ms delay between lights, higher is slower
- #define SABER_PAUSE_TOP 3000
- #define SABER_PAUSE_BOTTOM 1000
- #define SABER_BRIGHTNESS_NOMINAL 8
- #define SABER_BRIGHTNESS_MAX 255
- #define FIRE_TOTAL_LEDS 55
- #define FIRE_PIN 19
- #define FIRE_BRIGHTNESS_NOMINAL 127
- #define FIRE_BRIGHTNESS_MAX 255
- #define FIRE_SPEED 500// ms between fire refresh rate, higher is slower
- #define COOLING 70
- #define SPARKING 270
- #define FIRE_ROW_LEDS 11
- #define FIRE_ROW_COUNT 5
- #define BRIGHTBUTTON_PIN 17
- #define BRIGHT_DELAY 5000 // how many ms to stay in bright mode after button is pressed
- Adafruit_NeoPixel SaberStrip = Adafruit_NeoPixel(SABER_NUM_LEDS, SABER_PIN, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel FireStrip = Adafruit_NeoPixel(FIRE_TOTAL_LEDS, FIRE_PIN, NEO_GRB + NEO_KHZ800);
- Button BrightButton(BRIGHTBUTTON_PIN); // define the button that increases brightness
- unsigned long TimerMaster = 0; // master clock timer
- unsigned long TimerSaber = 0; // saber loop timer
- unsigned long TimerFire = 0; // fire update timer
- unsigned long TimerBright = 0; // bright-mode timer
- int SaberLoopCounter = 0; // loop counter for Saber
- bool SaberToggle = 0; // wipe to color or wipe to off
- int SaberBrightness = SABER_BRIGHTNESS_NOMINAL; // brightness value to be changed on button press
- int FireBrightness = FIRE_BRIGHTNESS_NOMINAL; // brightness value to be changed on button press
- byte heat[FIRE_TOTAL_LEDS]; // global array of heat values for all five rows
- /*
- // trying the saber code on the fire strip
- // to rule out hardware problems,
- unsigned long TimerSaber2 = 0; // saber loop timer
- int SaberLoopCounter2 = 0; // loop counter for Saber
- bool SaberToggle2 = 0; // wipe to color or wipe to off
- #define SABER_NUM_LEDS2 55
- #define SABER_COLOR2 0xFFb0db // use RGB (hex) color picker
- #define SABER_SPEED2 3 //ms delay between lights, higher is slower
- */
- void setup()
- {
- delay(1500); // sanity delay
- SaberStrip.begin(); // initialize saber strip
- SaberStrip.setBrightness(SaberBrightness);
- FireStrip.begin(); // initialize fire strip
- FireStrip.setBrightness(FireBrightness);
- BrightButton.begin();
- }
- void loop()
- {
- TimerMaster = millis();
- BrightButton.read();
- if (BrightButton.wasPressed())
- {
- // If the button was pressed, crank up the brightness for a certain amount of time
- SaberBrightness = SABER_BRIGHTNESS_MAX;
- FireBrightness = FIRE_BRIGHTNESS_MAX;
- TimerBright = (TimerMaster + BRIGHT_DELAY);
- }
- if (TimerMaster >= TimerBright) // If the brightness timer has aged out
- {
- // Reset both Fire and Saber brightness to nominal values
- SaberBrightness = SABER_BRIGHTNESS_NOMINAL;
- FireBrightness = FIRE_BRIGHTNESS_NOMINAL;
- }
- if (TimerMaster >= TimerSaber)
- {
- SaberStrip.setBrightness(SaberBrightness);
- saberPower();
- }
- if (TimerMaster >= TimerFire)
- {
- FireStrip.setBrightness(FireBrightness);
- // saberPower2();
- Fire2012(0, 0, random(COOLING * 0.8, COOLING * 1.2), random(SPARKING * 0.8, SPARKING * 1.2));
- // Fire2012(11, 1, random(COOLING * 0.8, COOLING * 1.2), random(SPARKING * 0.8, SPARKING * 1.2));
- // Fire2012(22, 0, random(COOLING * 0.8, COOLING * 1.2), random(SPARKING * 0.8, SPARKING * 1.2));
- // Fire2012(33, 1, random(COOLING * 0.8, COOLING * 1.2), random(SPARKING * 0.8, SPARKING * 1.2));
- // Fire2012(44, 0, random(COOLING * 0.8, COOLING * 1.2), random(SPARKING * 0.8, SPARKING * 1.2));
- TimerFire = (TimerMaster + FIRE_SPEED);
- FireStrip.show();
- }
- }
- void saberPower()
- {
- // Check to see if we're turning on (0) or turning off (1)
- if (SaberToggle == 0)
- {
- // Count from bottom to top, turning each one on
- // Wait for SABER_SPEED ms before turning the next one on
- if (SaberLoopCounter < SABER_NUM_LEDS)
- {
- SaberStrip.setPixelColor(SaberLoopCounter, SABER_COLOR);
- SaberStrip.show();
- TimerSaber = (TimerMaster + SABER_SPEED);
- SaberLoopCounter++;
- }
- // When top is reached, toggle the on/off
- // Then wait for SABER_PAUSE_TOP ms before turning off
- else
- {
- SaberToggle = !SaberToggle;
- TimerSaber = (TimerMaster + SABER_PAUSE_TOP);
- }
- }
- else
- {
- // Count from top to bottom, turning each one off
- // Wait for SABER_SPEED ms before turning the next one off
- if (SaberLoopCounter > 0)
- {
- SaberLoopCounter--;
- SaberStrip.setPixelColor(SaberLoopCounter, 0);
- SaberStrip.show();
- TimerSaber = (TimerMaster + SABER_SPEED);
- }
- // When top is reached, toggle the on/off
- // Then wait for SABER_PAUSE_TOP ms before turning off
- else
- {
- SaberToggle = !SaberToggle;
- TimerSaber = (TimerMaster + SABER_PAUSE_BOTTOM);
- }
- }
- }
- /*
- void saberPower2()
- {
- // Check to see if we're turning on (0) or turning off (1)
- if (SaberToggle2 == 0)
- {
- // Count from bottom to top, turning each one on
- // Wait for SABER_SPEED ms before turning the next one on
- if (SaberLoopCounter2 < SABER_NUM_LEDS2)
- {
- FireStrip.setPixelColor(SaberLoopCounter2, SABER_COLOR2);
- FireStrip.show();
- TimerSaber2 = (TimerMaster + SABER_SPEED2);
- SaberLoopCounter2++;
- }
- // When top is reached, toggle the on/off
- // Then wait for SABER_PAUSE_TOP ms before turning off
- else
- {
- SaberToggle2 = !SaberToggle2;
- TimerSaber2 = (TimerMaster + SABER_PAUSE_TOP);
- }
- }
- else
- {
- // Count from top to bottom, turning each one off
- // Wait for SABER_SPEED ms before turning the next one off
- if (SaberLoopCounter2 > 0)
- {
- SaberLoopCounter2--;
- FireStrip.setPixelColor(SaberLoopCounter2, 0);
- FireStrip.show();
- TimerSaber2 = (TimerMaster + SABER_SPEED2);
- }
- // When top is reached, toggle the on/off
- // Then wait for SABER_PAUSE_TOP ms before turning off
- else
- {
- SaberToggle2 = !SaberToggle2;
- TimerSaber2 = (TimerMaster + SABER_PAUSE_BOTTOM);
- }
- }
- }
- */
- void Fire2012(int LED_START_NUM, bool gReverseDirection, int cool, int spark)
- {
- // just set it all to a fixed value to see if anything will even light up
- for ( int i = 0; i < FIRE_TOTAL_LEDS; i++)
- {
- heat[i] = 128;
- }
- for ( int j = 0; j < FIRE_TOTAL_LEDS; j++)
- {
- FireStrip.setPixelColor(j, HeatColor(min(150, heat[j])));
- }
- FireStrip.show();
- }
- /*
- void Fire2012(int LED_START_NUM, bool gReverseDirection, int cool, int spark)
- {
- // Array of temperature readings at each simulation cell
- // static byte heat[FIRE_ROW_LEDS];
- // randomSeed(analogRead(0));
- // Step 1. Cool down every cell a little
- for ( int i = LED_START_NUM; i < (FIRE_ROW_LEDS + LED_START_NUM); i++)
- {
- heat[i] = qsub8( heat[i], random8(0, ((cool * 10) / FIRE_ROW_LEDS) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for ( int k = FIRE_ROW_LEDS - 1; k >= 2; k--)
- {
- heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if ( random8() < spark )
- {
- int y = random8(2);
- heat[LED_START_NUM + y] = qadd8( heat[LED_START_NUM + y], random8(160, 255) );
- }
- // Step 4. Map from heat cells to LED colors
- for ( int j = 0; j < FIRE_TOTAL_LEDS; j++)
- {
- FireStrip.setPixelColor(j, HeatColor(min(150, heat[j])));
- }
- FireStrip.show();
- */
- /*
- // Step 4. Map from heat cells to LED colors
- for ( int j = LED_START_NUM; j < (FIRE_ROW_LEDS + LED_START_NUM); j++)
- {
- CRGB color = HeatColor(min(150, heat[j - LED_START_NUM]));
- int pixelnumber;
- if ( gReverseDirection )
- {
- pixelnumber = ((FIRE_ROW_LEDS + LED_START_NUM) - 1) - (j - LED_START_NUM);
- }
- else
- {
- pixelnumber = j;
- }
- //firestrip[pixelnumber] = color;
- FireStrip.setPixelColor(pixelnumber, color);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement