Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Designed to drive an array of 8 strips of 25 WS2812b RGB LEDs with different display functions
- 0) Off No settings / no brightness control
- 1) Real fire No settings - potentiometer #2 immediately defaults to brightness control
- 2) Color Fire Setttings = goes through the rainbow hues to select the basic flame color
- 3) Rainbow Fire No settings - potentiometer #2 immediately defaults to brightness control
- 4) Barberpole No settings - potentiometer #2 immediately defaults to brightness control
- 5) Rainbow barberpole Setttings = goes through the rainbow hues to select the basic color
- 6) Rainbow No settings - potentiometer #2 immediately defaults to brightness control
- 7) Vertical rainbow No settings - potentiometer #2 immediately defaults to brightness control
- 8) Horizonatl Rainbow No settings - potentiometer #2 immediately defaults to brightness control
- 9) Heartbeat No settings - potentiometer #2 immediately defaults to brightness control
- 10) Color heartbeat Setttings = goes through the rainbow hues to select the basic color
- 11) Lighthouse No settings - potentiometer #2 immediately defaults to brightness control
- 12) Color lighthouse Setttings = goes through the rainbow hues to select the basic color
- 13) Color twinkle No settings - potentiometer #2 immediately defaults to brightness control
- 14) Monochrome Setttings = goes through the rainbow hues to select the basic color
- 15) White No settings - potentiometer #2 immediately defaults to brightness control
- ??) Fire flies (Singke or double spinning around)
- ??) Starry (Twinkles)
- ??) Matchlight (Fire from initial match strike to dying fire)
- 2 potentiometers on A0 and A1 provide control over the different display functions
- A0 always provide a 'Mode' control defining the general type of animation (Fire, Rainbow, Steady etc...)
- A1 provides a 'Settings' control that changes how the different 'modes' behave.
- A timed approach enables 2 (more could be implemented if necessary?) different controls with the same potentiometer.
- When a new mode is entered, a timer is started to enable the 'Settings' potentiometer to change a functional parameter.
- When the 'Settings' potentiometer is stable for at least 5 seconds, it's function changes to and stays as a global brightness control.
- */
- #include <FastLED.h>
- #define NUM_STRIPS 8
- #define NUM_LEDS_PER_STRIP 28
- #define FRAMES_PER_SECOND 120
- #define MAX_BRIGHTNESS 50
- byte brightness = 32;
- byte settings = 0;
- int settingstimeout1 = 5000; // Allow as much as 5 seconds to change the settings before locking it in
- int settingstimeout2 = 6000; // Allow as much as 5 seconds to change the settings before locking it in
- int ledMode = 4;
- unsigned long time = 0;
- #define FRAMES_PER_SECOND 100
- CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
- CRGB darkcolor;
- CRGB lightcolor;
- CRGBPalette16 gPalette = RainbowColors_p;
- #define STARTING_BRIGHTNESS 64
- #define FADE_IN_SPEED 32
- #define FADE_OUT_SPEED 16
- #define DENSITY 2 // Number needs to be very small as main loop is re-entered without any delays
- #define BUTTON_PIN 12
- enum { GETTING_DARKER = 0, GETTING_BRIGHTER = 1 };
- static byte heat[NUM_STRIPS][NUM_LEDS_PER_STRIP]; // Array of temperature readings at each simulation cell
- // There are two main parameters you can play with to control the look and
- // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
- // in step 3 above).
- //
- // COOLING: How much does the air cool as it rises?
- // Less cooling = taller flames. More cooling = shorter flames.
- // Default 55, suggested range 20-100
- #define COOLING 85
- // SPARKING: What chance (out of 255) is there that a new spark will be lit?
- // Higher chance = more roaring fire. Lower chance = more flickery fire.
- // Default 120, suggested range 50-200.
- byte SPARKING = 150;
- // Fire2012 with programmable Color Palette
- //
- // This code is the same fire simulation as the original "Fire2012",
- // but each heat cell's temperature is translated to color through a FastLED
- // programmable color palette, instead of through the "HeatColor(...)" function.
- //
- // Four different static color palettes are provided here, plus one dynamic one.
- //
- // The three static ones are:
- // 1. the FastLED built-in HeatColors_p -- this is the default, and it looks
- // pretty much exactly like the original Fire2012.
- //
- // To use any of the other palettes below, just "uncomment" the corresponding code.
- //
- // 2. a gradient from black to red to yellow to white, which is
- // visually similar to the HeatColors_p, and helps to illustrate
- // what the 'heat colors' palette is actually doing,
- // 3. a similar gradient, but in blue colors rather than red ones,
- // i.e. from black to blue to aqua to white, which results in
- // an "icy blue" fire effect,
- // 4. a simplified three-step gradient, from black to red to white, just to show
- // that these gradients need not have four components; two or
- // three are possible, too, even if they don't look quite as nice for fire.
- //
- // The dynamic palette shows how you can change the basic 'hue' of the
- // color palette every time through the loop, producing "rainbow fire".
- CRGBPalette16 gPal;
- #define NumberOfModes 16
- int val_0 = 0;
- int prevVal_0 = 128;
- int mode = 0;
- int mymode = 0;
- int oldmode = 0;
- int val_1 = 0;
- int prevVal_1 = 128;
- int buttonState = LOW;
- int ledState = -1;
- const int buttonPin = 12;
- long lastDebounceTime = 0; // the last time the output pin was toggled
- long debounceDelay = 500; // the debounce time; increase if the output flickers
- unsigned long keyPrevMillis = 0;
- const unsigned long keySampleIntervalMs = 25;
- byte longKeyPressCountMax = 80; // 80 * 25 = 2000 ms
- byte longKeyPressCount = 0;
- byte prevKeyState = HIGH; // button is active low
- void setup() {
- FastLED.addLeds<NEOPIXEL, 9>(leds[0], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 2>(leds[1], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 3>(leds[2], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 4>(leds[3], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 5>(leds[4], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 6>(leds[5], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 7>(leds[6], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<NEOPIXEL, 8>(leds[7], NUM_LEDS_PER_STRIP);
- FastLED.setBrightness(MAX_BRIGHTNESS);
- FastLED.setDither(0);
- Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
- // This first palette is the basic 'black body radiation' colors,
- // which run from black to red to bright yellow to white.
- // gPal = HeatColors_p;
- // These are other ways to set up the color palette for the 'fire'.
- // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::DarkOrange, CRGB::DarkOrange,
- // CRGB::DarkOrange, CRGB::DarkOrange, CRGB::DarkOrange, CRGB::Orange,
- // CRGB::Orange, CRGB::Orange, CRGB::Orange, CRGB::Yellow,
- // CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Yellow; // DimGray = 696969 Gray=808080 DarkGray=A9A9A9 LightGray=D3D3D3
- // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
- // Third, here's a simpler, three-step gradient, from black to red to white
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::White);
- // This is a custom palette to display full brightnees white LEDs only
- // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
- // gPal = CRGBPalette16( CRGB::White, CRGB::White, CRGB::White, CRGB::White);
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- //digitalWrite(buttonPin, LOW);
- }
- void loop(){
- random16_add_entropy( random()); // Add entropy to random number generator; we use a lot of it.
- //buttonState=digitalRead(buttonPin);
- byte currKeyState = digitalRead(BUTTON_PIN);
- if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
- shortKeyPress();
- }
- prevKeyState = currKeyState;
- Serial.println(buttonState);
- if ( (millis() - lastDebounceTime) > debounceDelay) {
- Serial.print("Mode = "); Serial.print(mymode);
- Serial.print(" Old Mode ="); Serial.println(oldmode);
- //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
- if ( (buttonState == HIGH) && (mymode == oldmode) ) {
- (mymode++);
- if (mymode >14) {(mymode =0);}
- oldmode = mymode;
- lastDebounceTime = millis(); //set the current time
- }
- else if ( (buttonState == HIGH) && (mode != oldmode) ) {
- //digitalWrite(ledPin, LOW); //turn LED off
- //lastDebounceTime = millis(); //set the current time
- }//close if/else
- }//close if(time buffer)
- //CheckPots();
- FastLED.setBrightness(MAX_BRIGHTNESS);
- switch(ledMode) {
- case 0: // OFF mode
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- FastLED.show(); // display this frame
- delay (1000);
- break;
- case 1: // Standard fire
- colorbarberpole();
- break;
- case 2: // Fire with selectable colors
- darkcolor = CHSV(settings,255,brightness*3/4); // pure hue, threequarter brightness
- lightcolor = CHSV(settings,128,brightness); // half 'whitened', full brightness
- gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB(brightness,brightness,brightness));
- FastLED.setBrightness(brightness/2);
- Fire2012WithPalette(); // run simulation frame, using palette colors
- break;
- case 3: // Fire with slowly changing colors
- static uint8_t hue = 0;
- hue++;
- darkcolor = CHSV(hue,255,brightness*3/4); // pure hue, threequarter brightness
- lightcolor = CHSV(hue,128,brightness); // half 'whitened', full brightness
- gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB(brightness,brightness,brightness));
- FastLED.setBrightness(brightness/2);
- Fire2012WithPalette(); // run simulation frame, using palette colors
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 4:
- barberpole();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 5:
- gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::DarkOrange, CRGB::DarkOrange,
- CRGB::DarkOrange, CRGB::DarkOrange, CRGB::DarkOrange, CRGB::Orange,
- CRGB::Orange, CRGB::Orange, CRGB::Orange, CRGB::Yellow,
- CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Yellow); // DimGray = 696969 Gray=808080 DarkGray=A9A9A9 LightGray=D3D3D3
- FastLED.setBrightness(brightness/2);
- Fire2012WithPalette();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 6:
- rainbow();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 7:
- verrainbow();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 8:
- horrainbow();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 9:
- FastLED.setBrightness(brightness/2);
- heartbeat();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 10:
- FastLED.setBrightness(brightness/2);
- colorheartbeat();
- break;
- case 11:
- lighthouse();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 12:
- colorlighthouse();
- break;
- case 13:
- FastLED.setBrightness(brightness);
- colortwinkle();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- break;
- case 14:
- monochrome();
- break;
- default:
- white();
- time = millis() - settingstimeout2; // Make sure we don't flash the lamp as no settings are available here !
- }
- // Add entropy to random number generator; we use a lot of it.
- // random16_add_entropy( random());
- // Fourth, the most sophisticated: this one sets up a new palette every
- // time through the loop, based on a hue that changes every time.
- // The palette is a gradient from black, to a dark color based on the hue,
- // to a light color based on the hue, to white.
- //
- // static uint8_t hue = 0;
- // hue++;
- // CRGB darkcolor = CHSV(hue,255,192); // pure hue, three-quarters brightness
- // CRGB lightcolor = CHSV(hue,128,255); // half 'whitened', full brightness
- // gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB::White);
- }
- // Fire2012 by Mark Kriegsman, July 2012
- // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
- //
- //
- // This basic one-dimensional 'fire' simulation works roughly as follows:
- // There's a underlying array of 'heat' cells, that model the temperature
- // at each point along the line. Every cycle through the simulation,
- // four steps are performed:
- // 1) All cells cool down a little bit, losing heat to the air
- // 2) The heat from each cell drifts 'up' and diffuses a little
- // 3) Sometimes randomly new 'sparks' of heat are added at the bottom
- // 4) The heat from each cell is rendered as a color into the leds array
- // The heat-to-color mapping uses a black-body radiation approximation.
- //
- // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
- //
- // This simulation scales it self a bit depending on NUM_LEDS; it should look
- // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
- //
- // I recommend running this simulation at anywhere from 30-100 frames per second,
- // meaning an interframe delay of about 10-35 milliseconds.
- //
- // Looks best on a high-density LED setup (60+ pixels/meter).
- //
- //
- void Fire2012WithPalette(){
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) { // Step 1. Cool down every cell a little
- heat[strip][i] = qsub8( heat[strip][i], random8(0, ((COOLING * 10) / NUM_LEDS_PER_STRIP) + 2));
- }
- for( int k= NUM_LEDS_PER_STRIP - 1; k >= 1; k--) { // Step 2. Heat from each cell drifts 'up' and diffuses a little
- heat[strip][k] = (heat[strip][k-1] + heat[strip][k-2] + heat[strip][k-2] ) / 3;
- }
- if( random8() < SPARKING ) { // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- int y = random8(7);
- heat[strip][y] = qadd8( heat[strip][y], random8(200,255) );
- }
- for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) { // Step 4. Map from heat cells to LED colors
- byte colorindex = scale8( heat[strip][j], 240); // Scale the heat value from 0-255 down to 0-240 for best results with color palettes.
- leds[strip][j] = ColorFromPalette( gPal, colorindex);
- }
- }
- FastLED.show(); // display this frame
- delay(1000 / FRAMES_PER_SECOND);
- }
- void barberpole(){
- for (int rotate = 0; rotate < NUM_STRIPS; rotate++){
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- int diag = strip+i+rotate;
- diag = diag % 8;
- switch(strip){
- case 0:
- leds[diag][i] = CRGB(brightness,0,0);
- break;
- case 1:
- leds[diag][i] = CRGB(brightness,0,0);
- break;
- case 2:
- leds[diag][i] = CRGB(brightness,brightness,brightness);
- break;
- case 3:
- leds[diag][i] = CRGB(brightness,brightness,brightness);
- break;
- case 4:
- leds[diag][i] = CRGB(0,0,brightness);
- break;
- case 5:
- leds[diag][i] = CRGB(0,0,brightness);
- break;
- case 6:
- leds[diag][i] = CRGB(brightness,brightness,brightness);
- break;
- case 7:
- leds[diag][i] = CRGB(brightness,brightness,brightness);
- break;
- }
- }
- }
- FastLED.show(); // display this frame
- delay (200);
- CheckPots(); // Added to prevent brightness setting lag.
- }
- }
- void colorbarberpole(){
- for (int rotate = 0; rotate < NUM_STRIPS; rotate++){
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- byte settings2 = settings + 85;
- byte settings3 = settings + 170;
- int diag = strip+i+rotate;
- diag = diag % 8;
- switch(strip){
- case 0:
- leds[diag][i] = CHSV(settings2,255,brightness);
- break;
- case 1:
- leds[diag][i] = CHSV(settings2,255,brightness);
- break;
- case 2:
- leds[diag][i] = CHSV(settings,255,brightness);
- break;
- case 3:
- leds[diag][i] = CHSV(settings,255,brightness);
- break;
- case 4:
- leds[diag][i] = CHSV(settings3,255,brightness);
- break;
- case 5:
- leds[diag][i] = CHSV(settings3,255,brightness);
- break;
- case 6:
- leds[diag][i] = CHSV(settings,255,brightness);
- break;
- case 7:
- leds[diag][i] = CHSV(settings,255,brightness);
- break;
- }
- }
- }
- FastLED.show(); // display this frame
- delay (200);
- CheckPots(); // Added to prevent brightness setting lag.
- }
- }
- void rainbow(){
- static byte rainbow_color = 0;
- byte rainbow_brightness = constrain(brightness,96,255);
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
- }
- }
- FastLED.show();
- FastLED.delay(10);
- rainbow_color++;
- }
- void verrainbow(){
- static byte rainbow_start = 0;
- static byte rainbow_color = 0;
- byte rainbow_brightness = constrain(brightness,96,255);
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
- }
- rainbow_color+=10;
- }
- FastLED.show();
- FastLED.delay(3);
- rainbow_color = rainbow_start++;
- }
- void horrainbow(){
- static byte rainbow_start = 0;
- static byte rainbow_color = 0;
- byte rainbow_brightness = constrain(brightness,96,255);
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
- }
- rainbow_color+=32;
- }
- FastLED.show();
- FastLED.delay(10);
- rainbow_color = rainbow_start++;
- }
- void heartbeat(){
- for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- for( int i = k; i >=0; i--) {
- int j = i-k;
- int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- leds[strip][i] = CRGB(result,result,result);
- }
- }
- FastLED.show();
- delay(30);
- }
- for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- for( int i = NUM_LEDS_PER_STRIP-1; i >= k; i--) {
- int j = i-k;
- int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- leds[strip][i] = CRGB(result,result,result);
- }
- }
- FastLED.show();
- delay(30);
- }
- delay(1000);
- }
- void colorheartbeat(){
- for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- for( int i = k; i >=0; i--) {
- int j = i-k;
- int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- leds[strip][i] = CHSV(settings,255,result);
- }
- }
- FastLED.show();
- delay(30);
- }
- for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- for( int i = NUM_LEDS_PER_STRIP-1; i >= k; i--) {
- int j = i-k;
- int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- leds[strip][i] = CHSV(settings,255,result);
- }
- }
- FastLED.show();
- delay(30);
- }
- delay(1000);
- }
- void lighthouse(){
- static int pos = 0; // position of the "fraction-based bar"
- static byte hue = 0; // color for Fractional Bar
- int width = 2; // width of each light bar, in whole pixels
- int InterframeDelay = 20; // ms
- for( int strip = 0; strip < NUM_STRIPS; strip++) { // clear the pixel buffer
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- int pixel = pos / 16; // convert from pos to raw pixel number
- uint8_t frac = pos & 0x0F; // extract the 'factional' part of the position
- uint8_t bright;
- for( int n = 0; n <= width; n++) {
- if( n == 0) bright = brightness - brightness*frac/16; // first pixel in the bar
- else if( n == width ) bright = brightness*frac/16; // last pixel in the bar
- else bright = brightness; // middle pixels... if any...
- for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {
- leds[pixel][j] += CRGB(bright,bright,bright);
- }
- pixel++;
- if( pixel == NUM_STRIPS){
- pixel = 0; // wrap around
- }
- }
- FastLED.show();
- FastLED.delay(InterframeDelay);
- pos++; // Update by 1/16th pixel every loop
- if( pos >= (NUM_STRIPS * 16)) pos -= (NUM_STRIPS * 16); // wrap around if past the end
- }
- void colorlighthouse(){
- static int pos = 0; // position of the "fraction-based bar"
- static byte hue = 0; // color for Fractional Bar
- int width = 2; // width of each light bar, in whole pixels
- int InterframeDelay = 10; // ms
- for( int strip = 0; strip < NUM_STRIPS; strip++) { // clear the pixel buffer
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
- }
- int pixel = pos / 16; // convert from pos to raw pixel number
- uint8_t frac = pos & 0x0F; // extract the 'factional' part of the position
- uint8_t bright;
- for( int n = 0; n <= width; n++) {
- if( n == 0) bright = brightness - brightness*frac/16; // first pixel in the bar
- else if( n == width ) bright = brightness*frac/16; // last pixel in the bar
- else bright = brightness; // middle pixels... if any...
- for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {
- leds[pixel][j] += CHSV( settings, 255, bright);
- }
- pixel++;
- if( pixel == NUM_STRIPS){
- pixel = 0; // wrap around
- }
- }
- FastLED.show();
- FastLED.delay(InterframeDelay);
- pos++; // Update by 1/16th pixel every loop
- if( pos >= (NUM_STRIPS * 16)) pos -= (NUM_STRIPS * 16); // wrap around if past the end
- }
- void monochrome(){
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- leds[strip][i] = CHSV(settings, 255, brightness);
- }
- }
- FastLED.show(); // display this frame
- delay (100);
- }
- void colortwinkle(){
- brightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED);
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- if( random8() < DENSITY ) {
- if( !leds[strip][i]) {
- leds[strip][i] = ColorFromPalette( gPalette, random8(), STARTING_BRIGHTNESS, NOBLEND);
- setPixelDirection(i, strip, GETTING_BRIGHTER);
- }
- }
- }
- }
- FastLED.show();
- FastLED.delay(20);
- }
- void brightenOrDarkenEachPixel( fract8 fadeUpAmount, fract8 fadeDownAmount)
- {
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- if( getPixelDirection(i,strip) == GETTING_DARKER) {
- leds[strip][i] = leds[strip][i].nscale8(255 - fadeDownAmount);
- }
- else {
- CRGB incrementalColor = leds[strip][i];
- leds[strip][i] = leds[strip][i] + incrementalColor.nscale8(fadeUpAmount);
- if( leds[strip][i].r == 255 || leds[strip][i].g == 255 || leds[strip][i].b == 255) {
- setPixelDirection(i, strip, GETTING_DARKER);
- }
- }
- }
- }
- }
- uint8_t directionFlags[NUM_LEDS_PER_STRIP];
- bool getPixelDirection( uint8_t i, uint8_t strip) {
- uint8_t index = i;
- uint8_t bitNum = strip;
- return bitRead( directionFlags[index], bitNum);
- }
- void setPixelDirection( uint8_t i, uint8_t strip, bool dir) {
- uint8_t index = i;
- uint8_t bitNum = strip;
- bitWrite( directionFlags[index], bitNum, dir);
- }
- void white(){
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- leds[strip][i] = CRGB(brightness,brightness,brightness);
- }
- }
- FastLED.show(); // display this frame
- delay (100);
- }
- void CheckPots(){
- val_0 = analogRead(0);
- val_1 = analogRead(1);
- if (abs(val_0-prevVal_0) >= 8){ // If potentiometer is tweaked sufficiently to change settings
- // pot_status();
- if (millis() > (time + 5000)){ // Give as much as 5 seconds to change settings before locking it in.
- brightness = map(val_0, 0, 1024, 0, 256);
- prevVal_0 = val_0;
- }
- else {
- time = millis(); // RE-start timer each time we enter to change settings
- settings = map(val_0, 0, 1024, 0, 256);
- brightness = 128; // Temporarily set brightness to 50%
- prevVal_0 = val_0;
- }
- }
- if (abs(val_1-prevVal_1) >= 8){ // If potentiometer is tweaked sufficiently to change modes
- // pot_status();
- time = millis(); // Start timer
- mode = map(val_1, 0, 1024, 0, NumberOfModes);
- prevVal_1 = val_1;
- }
- if (millis() > (time + settingstimeout1) && millis() < (time + settingstimeout2)){ // If we just got out of the settings period...
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
- }
- FastLED.show(); // Indicate it by flashing off the lamp 1/4 second
- delay (250);
- for( int strip = 0; strip < NUM_STRIPS; strip++) {
- fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(brightness, brightness, brightness));
- }
- FastLED.show(); // Indicate it by flashing on the lamp 1/4 second
- delay (250);
- time = millis() - settingstimeout2; // Make sure we don't flash again !
- }
- }
- void pot_status(){
- Serial.print("Value of pot 0 is: ");
- Serial.print(val_0);
- Serial.print(" Value of pot 1 is: ");
- Serial.print(val_1);
- Serial.print(" Value of mode is: ");
- Serial.print(mode);
- Serial.print(" Value of settings is: ");
- Serial.print(settings);
- Serial.print(" Value of brightness is: ");
- Serial.println(brightness);
- }
- void shortKeyPress() {
- ledMode++;
- if (ledMode > 14) {
- ledMode=0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment