Guest User

BarberPoleAllCode

a guest
Oct 6th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 29.21 KB | None | 0 0
  1. /*  Designed to drive an array of 8 strips of 25 WS2812b RGB LEDs with different display functions
  2.  0) Off                           No settings / no brightness control
  3.  1) Real fire                     No settings - potentiometer #2 immediately defaults to brightness control
  4.  2) Color Fire                    Setttings  = goes through the rainbow hues to select the basic flame color
  5.  3) Rainbow Fire                  No settings - potentiometer #2 immediately defaults to brightness control
  6.  4) Barberpole                    No settings - potentiometer #2 immediately defaults to brightness control
  7.  5) Rainbow barberpole            Setttings  = goes through the rainbow hues to select the basic color
  8.  6) Rainbow                       No settings - potentiometer #2 immediately defaults to brightness control
  9.  7) Vertical rainbow              No settings - potentiometer #2 immediately defaults to brightness control
  10.  8) Horizonatl Rainbow            No settings - potentiometer #2 immediately defaults to brightness control
  11.  9) Heartbeat                     No settings - potentiometer #2 immediately defaults to brightness control
  12. 10) Color heartbeat               Setttings  = goes through the rainbow hues to select the basic color
  13. 11) Lighthouse                    No settings - potentiometer #2 immediately defaults to brightness control
  14. 12) Color lighthouse              Setttings  = goes through the rainbow hues to select the basic color
  15. 13) Color twinkle                 No settings - potentiometer #2 immediately defaults to brightness control
  16. 14) Monochrome                    Setttings  = goes through the rainbow hues to select the basic color
  17. 15) White                         No settings - potentiometer #2 immediately defaults to brightness control
  18.  
  19. ??) Fire flies (Singke or double spinning around)
  20. ??) Starry (Twinkles)
  21. ??) Matchlight (Fire from initial match strike to dying fire)
  22.  
  23.  
  24.  2 potentiometers on A0 and A1 provide control over the different display functions
  25.  A0 always provide a 'Mode' control defining the general type of animation (Fire, Rainbow, Steady etc...)
  26.  A1 provides a 'Settings' control that changes how the different 'modes' behave.
  27.  
  28.  A timed approach enables 2 (more could be implemented if necessary?) different controls with the same potentiometer.
  29.  When a new mode is entered, a timer is started to enable the 'Settings' potentiometer to change a functional parameter.
  30.  When the 'Settings' potentiometer is stable for at least 5 seconds, it's function changes to and stays as a global brightness control.
  31.  */
  32.  
  33.  
  34. #include <FastLED.h>
  35.  
  36. #define NUM_STRIPS 8
  37. #define NUM_LEDS_PER_STRIP    28
  38. #define FRAMES_PER_SECOND 120
  39. #define MAX_BRIGHTNESS 50
  40.  
  41. byte brightness = 32;
  42. byte settings = 0;
  43. int settingstimeout1 = 5000;         // Allow as much as 5 seconds to change the settings before locking it in
  44. int settingstimeout2 = 6000;         // Allow as much as 5 seconds to change the settings before locking it in
  45. int ledMode = 4;
  46.  
  47. unsigned long time = 0;
  48.  
  49. #define FRAMES_PER_SECOND 100
  50.  
  51. CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
  52. CRGB darkcolor;
  53. CRGB lightcolor;
  54.  
  55. CRGBPalette16 gPalette = RainbowColors_p;
  56.  
  57. #define STARTING_BRIGHTNESS 64
  58. #define FADE_IN_SPEED       32
  59. #define FADE_OUT_SPEED      16
  60. #define DENSITY              2  // Number needs to be very small as main loop is re-entered without any delays
  61. #define BUTTON_PIN   12  
  62.  
  63. enum { GETTING_DARKER = 0, GETTING_BRIGHTER = 1 };
  64.  
  65. static byte heat[NUM_STRIPS][NUM_LEDS_PER_STRIP];                                   // Array of temperature readings at each simulation cell
  66.  
  67. // There are two main parameters you can play with to control the look and
  68. // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
  69. // in step 3 above).
  70. //
  71. // COOLING: How much does the air cool as it rises?
  72. // Less cooling = taller flames.  More cooling = shorter flames.
  73. // Default 55, suggested range 20-100
  74. #define COOLING  85
  75.  
  76.  
  77. // SPARKING: What chance (out of 255) is there that a new spark will be lit?
  78. // Higher chance = more roaring fire.  Lower chance = more flickery fire.
  79. // Default 120, suggested range 50-200.
  80. byte  SPARKING = 150;
  81.  
  82.  
  83. // Fire2012 with programmable Color Palette
  84. //
  85. // This code is the same fire simulation as the original "Fire2012",
  86. // but each heat cell's temperature is translated to color through a FastLED
  87. // programmable color palette, instead of through the "HeatColor(...)" function.
  88. //
  89. // Four different static color palettes are provided here, plus one dynamic one.
  90. //
  91. // The three static ones are:
  92. //   1. the FastLED built-in HeatColors_p -- this is the default, and it looks
  93. //      pretty much exactly like the original Fire2012.
  94. //
  95. //  To use any of the other palettes below, just "uncomment" the corresponding code.
  96. //
  97. //   2. a gradient from black to red to yellow to white, which is
  98. //      visually similar to the HeatColors_p, and helps to illustrate
  99. //      what the 'heat colors' palette is actually doing,
  100. //   3. a similar gradient, but in blue colors rather than red ones,
  101. //      i.e. from black to blue to aqua to white, which results in
  102. //      an "icy blue" fire effect,
  103. //   4. a simplified three-step gradient, from black to red to white, just to show
  104. //      that these gradients need not have four components; two or
  105. //      three are possible, too, even if they don't look quite as nice for fire.
  106. //
  107. // The dynamic palette shows how you can change the basic 'hue' of the
  108. // color palette every time through the loop, producing "rainbow fire".
  109.  
  110. CRGBPalette16 gPal;
  111.  
  112. #define NumberOfModes 16
  113.  
  114. int val_0 = 0;
  115. int prevVal_0 = 128;
  116. int mode = 0;
  117. int mymode = 0;
  118. int oldmode = 0;
  119. int val_1 = 0;
  120. int prevVal_1 = 128;
  121. int buttonState = LOW;
  122. int ledState = -1;
  123. const int buttonPin = 12;
  124.  
  125. long lastDebounceTime = 0;  // the last time the output pin was toggled
  126. long debounceDelay = 500;    // the debounce time; increase if the output flickers
  127.  
  128. unsigned long keyPrevMillis = 0;
  129. const unsigned long keySampleIntervalMs = 25;
  130. byte longKeyPressCountMax = 80;    // 80 * 25 = 2000 ms
  131. byte longKeyPressCount = 0;
  132.  
  133. byte prevKeyState = HIGH;         // button is active low
  134.  
  135. void setup() {
  136.  
  137.   FastLED.addLeds<NEOPIXEL, 9>(leds[0], NUM_LEDS_PER_STRIP);
  138.   FastLED.addLeds<NEOPIXEL, 2>(leds[1], NUM_LEDS_PER_STRIP);
  139.   FastLED.addLeds<NEOPIXEL, 3>(leds[2], NUM_LEDS_PER_STRIP);
  140.   FastLED.addLeds<NEOPIXEL, 4>(leds[3], NUM_LEDS_PER_STRIP);
  141.   FastLED.addLeds<NEOPIXEL, 5>(leds[4], NUM_LEDS_PER_STRIP);
  142.   FastLED.addLeds<NEOPIXEL, 6>(leds[5], NUM_LEDS_PER_STRIP);
  143.   FastLED.addLeds<NEOPIXEL, 7>(leds[6], NUM_LEDS_PER_STRIP);
  144.   FastLED.addLeds<NEOPIXEL, 8>(leds[7], NUM_LEDS_PER_STRIP);
  145.  
  146.   FastLED.setBrightness(MAX_BRIGHTNESS);
  147.   FastLED.setDither(0);
  148.  
  149.   Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  150.  
  151.   // This first palette is the basic 'black body radiation' colors,
  152.   // which run from black to red to bright yellow to white.
  153.   // gPal = HeatColors_p;
  154.  
  155.   // These are other ways to set up the color palette for the 'fire'.
  156.   // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
  157.   // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::DarkOrange, CRGB::DarkOrange,
  158.   //                       CRGB::DarkOrange, CRGB::DarkOrange, CRGB::DarkOrange, CRGB::Orange,
  159.   //                       CRGB::Orange, CRGB::Orange, CRGB::Orange, CRGB::Yellow,
  160.   //                       CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Yellow;          // DimGray = 696969 Gray=808080 DarkGray=A9A9A9 LightGray=D3D3D3
  161.  
  162.   // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow
  163.   // gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua,  CRGB::White);
  164.  
  165.   // Third, here's a simpler, three-step gradient, from black to red to white
  166.   // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::White);
  167.  
  168.   // This is a custom palette to display full brightnees white LEDs only
  169.   // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
  170.   // gPal = CRGBPalette16( CRGB::White, CRGB::White, CRGB::White, CRGB::White);
  171. pinMode(BUTTON_PIN, INPUT_PULLUP);
  172.  
  173. //digitalWrite(buttonPin, LOW);
  174.  
  175. }
  176.  
  177. void loop(){
  178.  
  179.   random16_add_entropy( random());        // Add entropy to random number generator; we use a lot of it.
  180.  
  181.  
  182.   //buttonState=digitalRead(buttonPin);
  183.  
  184.   byte currKeyState = digitalRead(BUTTON_PIN);
  185.  
  186.   if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
  187.     shortKeyPress();
  188.   }
  189.   prevKeyState = currKeyState;
  190.  
  191.   Serial.println(buttonState);
  192.  
  193.   if ( (millis() - lastDebounceTime) > debounceDelay) {
  194.   Serial.print("Mode = "); Serial.print(mymode);
  195.   Serial.print("     Old Mode ="); Serial.println(oldmode);
  196.     //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
  197.     if ( (buttonState == HIGH) && (mymode == oldmode) ) {
  198.      
  199.       (mymode++);
  200.       if (mymode >14) {(mymode =0);}
  201.       oldmode = mymode;
  202.       lastDebounceTime = millis(); //set the current time
  203.     }
  204.     else if ( (buttonState == HIGH) && (mode != oldmode) ) {
  205.  
  206.       //digitalWrite(ledPin, LOW); //turn LED off
  207.      
  208.       //lastDebounceTime = millis(); //set the current time
  209.     }//close if/else
  210.  
  211.   }//close if(time buffer)
  212.  
  213.   //CheckPots();
  214.  
  215.  
  216.   FastLED.setBrightness(MAX_BRIGHTNESS);
  217.  
  218.   switch(ledMode) {
  219.  
  220.   case 0:     // OFF mode
  221.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  222.       fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  223.     }
  224.     FastLED.show(); // display this frame
  225.     delay (1000);
  226.     break;
  227.  
  228.   case 1:     // Standard fire                                                              
  229.     colorbarberpole();
  230.     break;
  231.    
  232.    
  233.  
  234.   case 2:     // Fire with selectable colors
  235.     darkcolor  = CHSV(settings,255,brightness*3/4); // pure hue, threequarter brightness
  236.     lightcolor = CHSV(settings,128,brightness); // half 'whitened', full brightness
  237.     gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB(brightness,brightness,brightness));
  238.     FastLED.setBrightness(brightness/2);
  239.     Fire2012WithPalette(); // run simulation frame, using palette colors
  240.     break;
  241.  
  242.   case 3:     // Fire with slowly changing colors
  243.     static uint8_t hue = 0;
  244.     hue++;
  245.     darkcolor  = CHSV(hue,255,brightness*3/4); // pure hue, threequarter brightness
  246.     lightcolor = CHSV(hue,128,brightness); // half 'whitened', full brightness
  247.     gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB(brightness,brightness,brightness));
  248.     FastLED.setBrightness(brightness/2);
  249.     Fire2012WithPalette(); // run simulation frame, using palette colors
  250.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  251.     break;
  252.  
  253.   case 4:
  254.     barberpole();
  255.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  256.     break;
  257.  
  258.   case 5:
  259.     gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::DarkOrange, CRGB::DarkOrange,
  260.     CRGB::DarkOrange, CRGB::DarkOrange, CRGB::DarkOrange, CRGB::Orange,
  261.     CRGB::Orange, CRGB::Orange, CRGB::Orange, CRGB::Yellow,
  262.     CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Yellow);                     // DimGray = 696969 Gray=808080 DarkGray=A9A9A9 LightGray=D3D3D3
  263.     FastLED.setBrightness(brightness/2);
  264.     Fire2012WithPalette();
  265.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  266.     break;
  267.  
  268.   case 6:
  269.     rainbow();
  270.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  271.     break;
  272.  
  273.   case 7:
  274.     verrainbow();
  275.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  276.     break;
  277.  
  278.   case 8:
  279.     horrainbow();
  280.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  281.     break;
  282.  
  283.   case 9:
  284.     FastLED.setBrightness(brightness/2);
  285.     heartbeat();
  286.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  287.     break;
  288.  
  289.   case 10:
  290.     FastLED.setBrightness(brightness/2);
  291.     colorheartbeat();
  292.     break;
  293.  
  294.   case 11:
  295.     lighthouse();
  296.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  297.     break;
  298.  
  299.   case 12:
  300.     colorlighthouse();
  301.     break;
  302.  
  303.   case 13:
  304.     FastLED.setBrightness(brightness);
  305.     colortwinkle();
  306.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  307.     break;
  308.  
  309.   case 14:
  310.     monochrome();
  311.     break;
  312.  
  313.   default:
  314.     white();
  315.     time = millis() - settingstimeout2;                                          // Make sure we don't flash the lamp as no settings are available here !
  316.  
  317.   }
  318.  
  319.   // Add entropy to random number generator; we use a lot of it.
  320.   // random16_add_entropy( random());
  321.  
  322.   // Fourth, the most sophisticated: this one sets up a new palette every
  323.   // time through the loop, based on a hue that changes every time.
  324.   // The palette is a gradient from black, to a dark color based on the hue,
  325.   // to a light color based on the hue, to white.
  326.   //
  327.   // static uint8_t hue = 0;
  328.   // hue++;
  329.   // CRGB darkcolor  = CHSV(hue,255,192); // pure hue, three-quarters brightness
  330.   // CRGB lightcolor = CHSV(hue,128,255); // half 'whitened', full brightness
  331.   // gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB::White);
  332.  
  333. }
  334.  
  335.  
  336. // Fire2012 by Mark Kriegsman, July 2012
  337. // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
  338. //
  339. //
  340. // This basic one-dimensional 'fire' simulation works roughly as follows:
  341. // There's a underlying array of 'heat' cells, that model the temperature
  342. // at each point along the line.  Every cycle through the simulation,
  343. // four steps are performed:
  344. //  1) All cells cool down a little bit, losing heat to the air
  345. //  2) The heat from each cell drifts 'up' and diffuses a little
  346. //  3) Sometimes randomly new 'sparks' of heat are added at the bottom
  347. //  4) The heat from each cell is rendered as a color into the leds array
  348. //     The heat-to-color mapping uses a black-body radiation approximation.
  349. //
  350. // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
  351. //
  352. // This simulation scales it self a bit depending on NUM_LEDS; it should look
  353. // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
  354. //
  355. // I recommend running this simulation at anywhere from 30-100 frames per second,
  356. // meaning an interframe delay of about 10-35 milliseconds.
  357. //
  358. // Looks best on a high-density LED setup (60+ pixels/meter).
  359. //
  360. //
  361.  
  362. void Fire2012WithPalette(){
  363.  
  364.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  365.  
  366.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          // Step 1.  Cool down every cell a little
  367.       heat[strip][i] = qsub8( heat[strip][i],  random8(0, ((COOLING * 10) / NUM_LEDS_PER_STRIP) + 2));
  368.     }
  369.  
  370.     for( int k= NUM_LEDS_PER_STRIP - 1; k >= 1; k--) {                      // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  371.       heat[strip][k] = (heat[strip][k-1] + heat[strip][k-2] + heat[strip][k-2] ) / 3;
  372.     }
  373.  
  374.     if( random8() < SPARKING ) {                                  // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  375.       int y = random8(7);
  376.       heat[strip][y] = qadd8( heat[strip][y], random8(200,255) );
  377.     }
  378.  
  379.     for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {                          // Step 4.  Map from heat cells to LED colors
  380.       byte colorindex = scale8( heat[strip][j], 240);                      // Scale the heat value from 0-255 down to 0-240 for best results with color palettes.
  381.       leds[strip][j] = ColorFromPalette( gPal, colorindex);
  382.     }
  383.   }
  384.   FastLED.show(); // display this frame
  385.   delay(1000 / FRAMES_PER_SECOND);
  386. }
  387.  
  388. void barberpole(){
  389.  
  390.   for (int rotate = 0; rotate < NUM_STRIPS; rotate++){
  391.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  392.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  393.  
  394.         int diag = strip+i+rotate;
  395.         diag = diag % 8;
  396.  
  397.        
  398.         switch(strip){
  399.  
  400.         case 0:
  401.           leds[diag][i] = CRGB(brightness,0,0);
  402.           break;
  403.         case 1:
  404.           leds[diag][i] = CRGB(brightness,0,0);
  405.           break;
  406.         case 2:
  407.           leds[diag][i] = CRGB(brightness,brightness,brightness);
  408.           break;
  409.         case 3:
  410.           leds[diag][i] = CRGB(brightness,brightness,brightness);
  411.           break;
  412.         case 4:
  413.           leds[diag][i] = CRGB(0,0,brightness);
  414.           break;
  415.         case 5:
  416.           leds[diag][i] = CRGB(0,0,brightness);
  417.           break;
  418.         case 6:
  419.           leds[diag][i] = CRGB(brightness,brightness,brightness);
  420.           break;
  421.         case 7:
  422.           leds[diag][i] = CRGB(brightness,brightness,brightness);
  423.           break;
  424.         }
  425.  
  426.       }
  427.     }
  428.     FastLED.show(); // display this frame
  429.     delay (200);
  430.     CheckPots();    // Added to prevent brightness setting lag.                          
  431.   }
  432. }
  433.  
  434. void colorbarberpole(){
  435.  
  436.   for (int rotate = 0; rotate < NUM_STRIPS; rotate++){
  437.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  438.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  439.  
  440.         byte settings2 = settings + 85;
  441.         byte settings3 = settings + 170;
  442.  
  443.         int diag = strip+i+rotate;
  444.         diag = diag % 8;
  445.  
  446.         switch(strip){
  447.  
  448.         case 0:
  449.           leds[diag][i] = CHSV(settings2,255,brightness);
  450.           break;
  451.         case 1:
  452.           leds[diag][i] = CHSV(settings2,255,brightness);
  453.           break;
  454.         case 2:
  455.           leds[diag][i] = CHSV(settings,255,brightness);
  456.           break;
  457.         case 3:
  458.           leds[diag][i] = CHSV(settings,255,brightness);
  459.           break;
  460.         case 4:
  461.           leds[diag][i] = CHSV(settings3,255,brightness);
  462.           break;
  463.         case 5:
  464.           leds[diag][i] = CHSV(settings3,255,brightness);
  465.           break;
  466.         case 6:
  467.           leds[diag][i] = CHSV(settings,255,brightness);
  468.           break;
  469.         case 7:
  470.           leds[diag][i] = CHSV(settings,255,brightness);
  471.           break;
  472.         }
  473.  
  474.       }
  475.     }
  476.     FastLED.show(); // display this frame
  477.     delay (200);
  478.     CheckPots();    // Added to prevent brightness setting lag.                          
  479.   }
  480. }
  481.  
  482. void rainbow(){
  483.  
  484.   static byte rainbow_color = 0;
  485.   byte rainbow_brightness = constrain(brightness,96,255);
  486.  
  487.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  488.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  489.       leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
  490.     }
  491.   }
  492.   FastLED.show();
  493.   FastLED.delay(10);
  494.   rainbow_color++;
  495. }
  496.  
  497.  
  498. void verrainbow(){
  499.  
  500.   static byte rainbow_start = 0;
  501.   static byte rainbow_color = 0;
  502.   byte rainbow_brightness = constrain(brightness,96,255);
  503.  
  504.   for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  505.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  506.        leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
  507.     }
  508.   rainbow_color+=10;
  509.  }
  510.   FastLED.show();
  511.   FastLED.delay(3);
  512.   rainbow_color = rainbow_start++;
  513. }
  514.  
  515. void horrainbow(){
  516.  
  517.   static byte rainbow_start = 0;
  518.   static byte rainbow_color = 0;
  519.   byte rainbow_brightness = constrain(brightness,96,255);
  520.  
  521.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  522.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  523.        leds[strip][i] = CHSV(rainbow_color, 255, rainbow_brightness);
  524.     }
  525.     rainbow_color+=32;
  526.  }
  527.   FastLED.show();
  528.   FastLED.delay(10);
  529.   rainbow_color = rainbow_start++;
  530. }
  531.  
  532. void heartbeat(){
  533.  
  534.   for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
  535.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  536.       fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  537.     }
  538.     for( int i = k; i >=0; i--) {
  539.       int j = i-k;
  540.       int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
  541.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  542.         leds[strip][i] = CRGB(result,result,result);
  543.       }
  544.     }
  545.     FastLED.show();
  546.     delay(30);
  547.   }
  548.  
  549.   for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
  550.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  551.       fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  552.     }
  553.     for( int i = NUM_LEDS_PER_STRIP-1; i >= k; i--) {
  554.       int j = i-k;
  555.       int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
  556.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  557.         leds[strip][i] = CRGB(result,result,result);
  558.       }
  559.     }
  560.     FastLED.show();
  561.     delay(30);
  562.   }
  563.  
  564.   delay(1000);
  565. }
  566.  
  567. void colorheartbeat(){
  568.  
  569.   for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
  570.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  571.       fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  572.     }
  573.     for( int i = k; i >=0; i--) {
  574.       int j = i-k;
  575.       int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
  576.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  577.         leds[strip][i] = CHSV(settings,255,result);
  578.       }
  579.     }
  580.     FastLED.show();
  581.     delay(30);
  582.   }
  583.  
  584.   for( int k = 0; k < NUM_LEDS_PER_STRIP; k++) {
  585.     for( int strip = 0; strip < NUM_STRIPS; strip++) {
  586.       fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  587.     }
  588.     for( int i = NUM_LEDS_PER_STRIP-1; i >= k; i--) {
  589.       int j = i-k;
  590.       int result = quadwave8(map(j,0,NUM_LEDS_PER_STRIP,0,255));
  591.       for( int strip = 0; strip < NUM_STRIPS; strip++) {
  592.         leds[strip][i] = CHSV(settings,255,result);
  593.       }
  594.     }
  595.     FastLED.show();
  596.     delay(30);
  597.   }
  598.  
  599.   delay(1000);
  600. }
  601.  
  602. void lighthouse(){
  603.  
  604.   static int pos = 0;          // position of the "fraction-based bar"
  605.   static byte hue = 0;          // color for Fractional Bar
  606.   int width  = 2;               // width of each light bar, in whole pixels
  607.   int InterframeDelay = 20;     // ms
  608.  
  609.   for( int strip = 0; strip < NUM_STRIPS; strip++) {                // clear the pixel buffer
  610.     fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  611.   }      
  612.  
  613.   int pixel = pos / 16; // convert from pos to raw pixel number
  614.   uint8_t frac = pos & 0x0F; // extract the 'factional' part of the position
  615.   uint8_t bright;
  616.  
  617.   for( int n = 0; n <= width; n++) {
  618.     if( n == 0) bright = brightness - brightness*frac/16;        // first pixel in the bar
  619.     else if( n == width ) bright = brightness*frac/16;      // last pixel in the bar
  620.     else bright = brightness;                             // middle pixels...   if any...        
  621.  
  622.     for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {        
  623.       leds[pixel][j] += CRGB(bright,bright,bright);
  624.     }
  625.    
  626.     pixel++;
  627.     if( pixel == NUM_STRIPS){
  628.       pixel = 0; // wrap around
  629.     }
  630.   }
  631.  
  632.   FastLED.show();
  633.   FastLED.delay(InterframeDelay);
  634.  
  635.   pos++;                                                    // Update by 1/16th pixel every loop
  636.   if( pos >= (NUM_STRIPS * 16)) pos -= (NUM_STRIPS * 16);   // wrap around if past the end
  637.  
  638. }
  639.  
  640. void colorlighthouse(){
  641.  
  642.   static int pos = 0;          // position of the "fraction-based bar"
  643.   static byte hue = 0;          // color for Fractional Bar
  644.   int width  = 2;               // width of each light bar, in whole pixels
  645.   int InterframeDelay = 10;     // ms
  646.  
  647.   for( int strip = 0; strip < NUM_STRIPS; strip++) {                // clear the pixel buffer
  648.     fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0) );
  649.   }      
  650.  
  651.   int pixel = pos / 16; // convert from pos to raw pixel number
  652.   uint8_t frac = pos & 0x0F; // extract the 'factional' part of the position
  653.   uint8_t bright;
  654.  
  655.   for( int n = 0; n <= width; n++) {
  656.     if( n == 0) bright = brightness - brightness*frac/16;        // first pixel in the bar
  657.     else if( n == width ) bright = brightness*frac/16;      // last pixel in the bar
  658.     else bright = brightness;                             // middle pixels...   if any...        
  659.  
  660.     for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {        
  661.       leds[pixel][j] += CHSV( settings, 255, bright);
  662.     }
  663.    
  664.     pixel++;
  665.     if( pixel == NUM_STRIPS){
  666.       pixel = 0; // wrap around
  667.     }
  668.   }
  669.  
  670.   FastLED.show();
  671.   FastLED.delay(InterframeDelay);
  672.  
  673.   pos++;                                                    // Update by 1/16th pixel every loop
  674.   if( pos >= (NUM_STRIPS * 16)) pos -= (NUM_STRIPS * 16);   // wrap around if past the end
  675.  
  676. }
  677.  
  678. void monochrome(){
  679.  
  680.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  681.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  682.       leds[strip][i] = CHSV(settings, 255, brightness);
  683.     }
  684.   }
  685.  
  686.   FastLED.show(); // display this frame
  687.   delay (100);
  688. }
  689.  
  690. void colortwinkle(){
  691.  
  692.   brightenOrDarkenEachPixel( FADE_IN_SPEED, FADE_OUT_SPEED);
  693.  
  694.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  695.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  696.       if( random8() < DENSITY ) {
  697.         if( !leds[strip][i]) {
  698.           leds[strip][i] = ColorFromPalette( gPalette, random8(), STARTING_BRIGHTNESS, NOBLEND);
  699.           setPixelDirection(i, strip, GETTING_BRIGHTER);
  700.         }
  701.       }
  702.     }
  703.   }
  704.   FastLED.show();  
  705.   FastLED.delay(20);
  706. }
  707.  
  708. void brightenOrDarkenEachPixel( fract8 fadeUpAmount, fract8 fadeDownAmount)
  709. {
  710.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  711.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  712.       if( getPixelDirection(i,strip) == GETTING_DARKER) {
  713.         leds[strip][i] = leds[strip][i].nscale8(255 - fadeDownAmount);
  714.       }
  715.       else {
  716.         CRGB incrementalColor = leds[strip][i];
  717.         leds[strip][i] = leds[strip][i] + incrementalColor.nscale8(fadeUpAmount);
  718.         if( leds[strip][i].r == 255 || leds[strip][i].g == 255 || leds[strip][i].b == 255) {
  719.           setPixelDirection(i, strip, GETTING_DARKER);
  720.         }
  721.       }
  722.     }
  723.   }
  724. }
  725.  
  726. uint8_t  directionFlags[NUM_LEDS_PER_STRIP];
  727.  
  728. bool getPixelDirection( uint8_t i,  uint8_t strip) {
  729.   uint8_t index = i;
  730.   uint8_t  bitNum = strip;
  731.   return bitRead( directionFlags[index], bitNum);
  732. }
  733.  
  734. void setPixelDirection( uint8_t i,  uint8_t strip, bool dir) {
  735.   uint8_t index = i;
  736.   uint8_t  bitNum = strip;
  737.   bitWrite( directionFlags[index], bitNum, dir);
  738. }
  739.  
  740. void white(){
  741.  
  742.   for( int strip = 0; strip < NUM_STRIPS; strip++) {
  743.     for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {                          
  744.       leds[strip][i] = CRGB(brightness,brightness,brightness);
  745.     }
  746.   }
  747.   FastLED.show(); // display this frame
  748.   delay (100);
  749. }
  750.  
  751.  
  752.  
  753.  
  754. void CheckPots(){
  755.  
  756.   val_0 = analogRead(0);
  757.   val_1 = analogRead(1);
  758.  
  759.   if (abs(val_0-prevVal_0) >= 8){                          // If potentiometer is tweaked sufficiently to change settings
  760.  
  761.     // pot_status();
  762.  
  763.     if (millis() > (time + 5000)){                          // Give as much as 5 seconds to change settings before locking it in.
  764.       brightness = map(val_0, 0, 1024, 0, 256);
  765.       prevVal_0 = val_0;
  766.     }
  767.     else {
  768.       time = millis();                                       // RE-start timer each time we enter to change settings
  769.       settings = map(val_0, 0, 1024, 0, 256);
  770.       brightness = 128;                                      // Temporarily set brightness to 50%
  771.       prevVal_0 = val_0;
  772.     }
  773.   }
  774.  
  775.   if (abs(val_1-prevVal_1) >= 8){                              // If potentiometer is tweaked sufficiently to change modes
  776.  
  777.     // pot_status();
  778.  
  779.     time = millis();                              // Start timer
  780.     mode = map(val_1, 0, 1024, 0, NumberOfModes);
  781.     prevVal_1 = val_1;
  782.   }
  783.  
  784.   if (millis() > (time + settingstimeout1) && millis() < (time + settingstimeout2)){   // If we just got out of the settings period...
  785.        
  786.         for( int strip = 0; strip < NUM_STRIPS; strip++) {
  787.           fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));    
  788.         }
  789.         FastLED.show();                                                 // Indicate it by flashing off the lamp 1/4 second
  790.         delay (250);
  791.        
  792.         for( int strip = 0; strip < NUM_STRIPS; strip++) {
  793.           fill_solid(leds[strip], NUM_LEDS_PER_STRIP, CRGB(brightness, brightness, brightness));    
  794.         }
  795.         FastLED.show();                                                 // Indicate it by flashing on the lamp 1/4 second
  796.         delay (250);
  797.        
  798.         time = millis() - settingstimeout2;                             // Make sure we don't flash again !
  799.       }
  800. }
  801.  
  802. void pot_status(){
  803.  
  804.   Serial.print("Value of pot 0 is: ");
  805.   Serial.print(val_0);
  806.   Serial.print("     Value of pot 1 is: ");
  807.   Serial.print(val_1);
  808.  
  809.   Serial.print("     Value of mode is: ");
  810.   Serial.print(mode);
  811.   Serial.print("     Value of settings is: ");
  812.   Serial.print(settings);
  813.   Serial.print("     Value of brightness is: ");
  814.   Serial.println(brightness);
  815. }
  816.  
  817. void shortKeyPress() {
  818.   ledMode++;
  819.   if (ledMode > 14) {
  820.     ledMode=0;
  821.   }  
  822. }
Advertisement
Add Comment
Please, Sign In to add comment