Advertisement
Guest User

MyFirstArch_2016

a guest
Jan 15th, 2017
9,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.64 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. // Good Reference!
  4. // http://fastled.io/docs/3.1/group___colorutils.html#gafcc7dac88e25736ebc49a9faf2a1c2e2
  5.  
  6.  
  7. #define DATA_PIN 4
  8. #define BRIGHTNESS_PIN A1
  9. //#define COLOR_ORDER BRG // this might be OK for strip light, but not for each pixel
  10. //#define COLOR_ORDER GRB
  11. #define COLOR_ORDER RGB
  12. #define LED_TYPE WS2812
  13. #define NUM_LEDS 62
  14. #define VOLTS 12
  15.  
  16. #define FRAMES_PER_SECOND 120
  17.  
  18.  
  19.  
  20. // brightness control added 3/6/2016
  21. // original limits:
  22. //#define MASTER_BRIGHTNESS 128 // Set the master brigtness value [should be greater then min_brightness value].
  23. //#define MIN_BRIGHTNESS 30 // Set a minimum brightness level.
  24. #define MASTER_BRIGHTNESS 192 // Set the master brigtness value [should be greater then min_brightness value].
  25. #define MIN_BRIGHTNESS 10 // Set a minimum brightness level.
  26. int potValA; // Variable to store potentiometer A value (for brightness A)
  27. uint8_t brightnessa; // Mapped master brightness for color A based on potentiometer reading.
  28.  
  29. #define NUM_VIRTUAL_LEDS NUM_LEDS+1
  30. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  31. CRGB leds[NUM_VIRTUAL_LEDS];
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. // variables for marque_v3
  39. uint16_t holdTime = 60; // Milliseconds to hold position before advancing.
  40. uint8_t spacing = 20; // Sets pixel spacing. [Use 2 or greater]
  41. int8_t delta = 1; // Sets forward or backwards direction amount. (Can be negative.)
  42. uint8_t width = 5; // Can increase the number of pixels (width) of the chase. [1 or greater]
  43.  
  44. uint8_t hue = 60; // Starting color (marque_v3)
  45.  
  46. boolean fadingTail = 1; // Add fading tail? [1=true, 0=falue]
  47. //uint8_t fadeRate = 150; // How fast to fade out tail. [0-255]
  48. uint8_t fadeRate = 70; // How fast to fade out tail. [0-255]
  49.  
  50. uint8_t hue2_shift = 60; // Hue shift for secondary color. Use 0 for no shift. [0-255]
  51. boolean DEBUG = 0; // Print some info to serial monitor. [1=true, 0=falue]
  52.  
  53. int16_t pos; // Pixel position.
  54. int8_t advance; // Stores the advance amount.
  55. uint8_t color; // Stores a hue color.
  56.  
  57.  
  58. // variables for Twinkle
  59. CRGBPalette16 gCurrentPalette;
  60. CRGBPalette16 gTargetPalette;
  61.  
  62. // How often to change color palettes.
  63. #define SECONDS_PER_PALETTE 15 // 30
  64. // Also: toward the bottom of the file is an array
  65. // called "ActivePaletteList" which controls which color
  66. // palettes are used; you can add or remove color palettes
  67. // from there freely.
  68.  
  69.  
  70.  
  71. // =============================================================================
  72. // setup routine
  73. // =============================================================================
  74. // put your setup code here, to run once:
  75. void setup() {
  76. delay(3000); // 3 second delay for recovery
  77. Serial.begin(57600);
  78.  
  79. // FastLED.setMaxPowerInVoltsAndMilliamps( VOLTS, NUM_LEDS*40);
  80. // FastLED.setMaxPowerInVoltsAndMilliamps( VOLTS, 4000);
  81.  
  82. // tell FastLED about the LED strip configuration
  83. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  84.  
  85. FastLED.setBrightness(MASTER_BRIGHTNESS);
  86.  
  87. // for Twinkle
  88. chooseNextColorPalette(gTargetPalette);
  89. }
  90.  
  91.  
  92. // List of patterns to cycle through. Each is defined as a separate function below.
  93. typedef void (*SimplePatternList[])();
  94. //SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
  95. //SimplePatternList gPatterns = { fill_solid_color, trace_inner_star, rainbow, sinelon, trace_star, juggle, bpm };
  96. //SimplePatternList gPatterns = { fill_solid_color, trace_inner_star, trace_star, gradient_fill };
  97. //SimplePatternList gPatterns = { gradient_fill_2, sinelon, fill_solid_color, trace_inner_star, juggle, trace_star, rainbow, bpm };
  98.  
  99. // I love these 4 patterns -- this is a great base:
  100. // SimplePatternList gPatterns = { gradient_fill_2, fill_solid_color, trace_inner_star, trace_star };
  101. // Tjese are 4 patterns are very energetic, they should be used intermittenly within the whole solution, maybe 1 per 2 above?
  102. // SimplePatternList gPatterns = { rainbow, sinelon, juggle, bpm };
  103.  
  104. // 11/23/2016 ~ these are patterns for star -- some don't make sense for arch
  105. //SimplePatternList gPatterns = { gradient_fill_2, fill_solid_color, trace_inner_star, trace_star };
  106.  
  107. // 11/23/2016 good arch patterns -- maybe better sort order
  108. //SimplePatternList gPatterns = { gradient_fill, rainbow, sinelon, juggle, bpm, fill_solid_color };
  109. //SimplePatternList gPatterns = { gradient_fill, bpm, rainbow, sinelon, fill_solid_color, juggle };
  110. //SimplePatternList gPatterns = { drawTwinkles, marque_v3, gradient_fill, bpm, sinelon, juggle };
  111. // 12/11/16 removed Gradient Fill,, bmp, sinelon - it was too "rainbowy"
  112. //SimplePatternList gPatterns = { marque_v3, juggle }; // <-- version recorded to YouTube 12/12/16
  113. SimplePatternList gPatterns = { drawTwinkles, marque_v3, juggle, sinelon };
  114.  
  115.  
  116.  
  117. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  118. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  119.  
  120.  
  121.  
  122. // =============================================================================
  123. // loop routine
  124. // =============================================================================
  125. // put your main code here, to run repeatedly:
  126. void loop() {
  127.  
  128. // brightness control
  129. /*
  130. potValA = analogRead(BRIGHTNESS_PIN); // Read potentiometer B (for brightness).
  131. //Serial.println (potValA);
  132. brightnessa = map(potValA, 0, 1023, MIN_BRIGHTNESS, MASTER_BRIGHTNESS);
  133. // Map value between min_brightness and MASTER brightness values.
  134. // Note: We are limiting the lowest possible brightness value to the
  135. // min_brightness value assigned up top.
  136. FastLED.setBrightness(brightnessa);
  137. //Serial.println (brightnessa);
  138. */
  139.  
  140.  
  141. // for Twinkle
  142. // Call the current pattern function once, updating the 'leds' array
  143. gPatterns[gCurrentPatternNumber]();
  144.  
  145. // insert a delay to keep the framerate modest
  146. FastLED.delay(1000/FRAMES_PER_SECOND);
  147.  
  148.  
  149. // do some periodic updates
  150. EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  151. EVERY_N_SECONDS( 25 ) { nextPattern(); } // change patterns periodically
  152.  
  153. // for marque_v3
  154. EVERY_N_SECONDS(7){ // Demo: Change the hue every N seconds.
  155. hue = hue + random8(30,61); // Shift the hue to something new.
  156. }
  157.  
  158. EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
  159. chooseNextColorPalette( gTargetPalette );
  160. }
  161.  
  162. EVERY_N_MILLISECONDS( 10 ) {
  163. nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 12);
  164. }
  165.  
  166. // send the 'leds' array out to the actual LED strip
  167. FastLED.show();
  168. }
  169.  
  170.  
  171.  
  172. // =============================================================================
  173. // Sub-Routines
  174. // =============================================================================
  175.  
  176.  
  177. void nextPattern()
  178. {
  179. // add one to the current pattern number, and wrap around at the end
  180. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  181. }
  182.  
  183.  
  184. void fill_solid_color()
  185. {
  186.  
  187. uint8_t hue1 = random8(255);
  188. uint8_t hue2 = random8(255);
  189.  
  190. for (int i=0; i<NUM_LEDS; i++) {
  191. /*
  192. Serial.println (i);
  193. leds[i] = CRGB::Red;
  194. leds[i-1] = CRGB::Blue;
  195. FastLED.show();
  196. leds[i] = CRGB::Black;
  197. */
  198. leds[i] = CHSV( hue1, 255, 255);
  199. leds[i-1] = CHSV( hue2, 255, 255);
  200. //FastLED.show();
  201. leds[i] = CRGB::Black;
  202.  
  203. delay(30);
  204. }
  205. }
  206.  
  207. void fill_black()
  208. {
  209. FastLED.clear();
  210. //fill_solid(leds, NUM_LEDS, CRGB::Black);
  211. }
  212.  
  213.  
  214. void rainbow()
  215. {
  216. // FastLED's built-in rainbow generator
  217. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  218. }
  219.  
  220.  
  221. void sinelon()
  222. {
  223. // a colored dot sweeping back and forth, with fading trails
  224. fadeToBlackBy( leds, NUM_LEDS, 20);
  225. int pos = beatsin16(13,0,NUM_LEDS);
  226. leds[pos] += CHSV( gHue, 255, 192);
  227. }
  228.  
  229. void bpm()
  230. {
  231. // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  232. uint8_t BeatsPerMinute = 62;
  233. CRGBPalette16 palette = PartyColors_p;
  234. uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  235. for( int i = 0; i < NUM_LEDS; i++) { //9948
  236. leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  237. }
  238. }
  239.  
  240.  
  241. void juggle() {
  242. // eight colored dots, weaving in and out of sync with each other
  243. fadeToBlackBy( leds, NUM_LEDS, 20);
  244. byte dothue = 0;
  245. for( int i = 0; i < 8; i++) {
  246. leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  247. dothue += 32;
  248. }
  249. }
  250.  
  251.  
  252. // draws a line that fades between 2 random colors
  253. // TODO: Add logic to rotate the starting point
  254. void gradient_fill() {
  255.  
  256. // uint8_t hue1 = 60;
  257. // uint8_t hue2 = random8(255);
  258. uint8_t hue1 = random8(255);
  259. uint8_t hue2 = hue1 + random8(30,61);
  260.  
  261. for( int i = 0; i < NUM_LEDS; i++){
  262. //fill_gradient (leds, 0, CHSV(0, 255, 255), i, CHSV(96, 255, 255), SHORTEST_HUES);
  263. fill_gradient (leds, 0, CHSV(hue1, 255, 255), i, CHSV(hue2, 255, 255), SHORTEST_HUES);
  264. delay(15);
  265. FastLED.show();
  266. // FastLED.clear();
  267. }
  268. }
  269.  
  270.  
  271.  
  272. // Adapted from code by Marc Miller. Original Header:
  273. //
  274. //***************************************************************
  275. // Marquee fun (v3)
  276. // Pixel position down the strip comes from this formula:
  277. // pos = spacing * (i-1) + spacing
  278. // i starts at 0 and is incremented by +1 up to NUM_LEDS/spacing.
  279. //
  280. // Marc Miller, May 2016
  281. //***************************************************************
  282. void marque_v3() {
  283.  
  284.  
  285. for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){
  286. for (uint8_t w = 0; w<width; w++){
  287. pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS;
  288. if ( w % 2== 0 ){ // Is w even or odd?
  289. color = hue;
  290. } else {
  291. color = hue + hue2_shift;
  292. }
  293.  
  294. leds[pos] = CHSV(color,255,255);
  295. }
  296.  
  297. if (DEBUG==1) { // Print out lit pixels if DEBUG is true.
  298. Serial.print(" "); Serial.print(pos);
  299. }
  300. delay(10);
  301. }
  302. if (DEBUG==1) { Serial.println(" "); }
  303. FastLED.show();
  304.  
  305. // Fade out tail or set back to black for next loop around.
  306. if (fadingTail == 1) {
  307. fadeToBlackBy(leds, NUM_LEDS,fadeRate);
  308. } else {
  309. for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){
  310. for (uint8_t w = 0; w<width; w++){
  311. pos = (spacing * (i-1) + spacing + advance + w) % NUM_LEDS;
  312. leds[pos] = CRGB::Black;
  313. }
  314. }
  315. }
  316.  
  317. // Advance pixel postion down strip, and rollover if needed.
  318. advance = (advance + delta + NUM_LEDS) % NUM_LEDS;
  319. }
  320.  
  321.  
  322.  
  323.  
  324.  
  325. // ===================
  326. // Adopted from Mark Kriegsman's Twinkle-Lights 2015
  327. // G+: https://plus.google.com/u/0/112916219338292742137/posts/XWiEEeDxFWZ?sfc=true
  328. // CODE: https://gist.github.com/kriegsman/756ea6dcae8e30845b5a
  329.  
  330. // TwinkleFOX: Twinkling 'holiday' lights that fade in and out.
  331. // Colors are chosen from a palette; a few palettes are provided.
  332. //
  333. // This December 2015 implementation improves on the December 2014 version
  334. // in several ways:
  335. // - smoother fading, compatible with any colors and any palettes
  336. // - easier control of twinkle speed and twinkle density
  337. // - supports an optional 'background color'
  338. // - takes even less RAM: zero RAM overhead per pixel
  339. // - illustrates a couple of interesting techniques (uh oh...)
  340. //
  341. // The idea behind this (new) implementation is that there's one
  342. // basic, repeating pattern that each pixel follows like a waveform:
  343. // The brightness rises from 0..255 and then falls back down to 0.
  344. // The brightness at any given point in time can be determined as
  345. // as a function of time, for example:
  346. // brightness = sine( time ); // a sine wave of brightness over time
  347. //
  348. // So the way this implementation works is that every pixel follows
  349. // the exact same wave function over time. In this particular case,
  350. // I chose a sawtooth triangle wave (triwave8) rather than a sine wave,
  351. // but the idea is the same: brightness = triwave8( time ).
  352. //
  353. // Of course, if all the pixels used the exact same wave form, and
  354. // if they all used the exact same 'clock' for their 'time base', all
  355. // the pixels would brighten and dim at once -- which does not look
  356. // like twinkling at all.
  357. //
  358. // So to achieve random-looking twinkling, each pixel is given a
  359. // slightly different 'clock' signal. Some of the clocks run faster,
  360. // some run slower, and each 'clock' also has a random offset from zero.
  361. // The net result is that the 'clocks' for all the pixels are always out
  362. // of sync from each other, producing a nice random distribution
  363. // of twinkles.
  364. //
  365. // The 'clock speed adjustment' and 'time offset' for each pixel
  366. // are generated randomly. One (normal) approach to implementing that
  367. // would be to randomly generate the clock parameters for each pixel
  368. // at startup, and store them in some arrays. However, that consumes
  369. // a great deal of precious RAM, and it turns out to be totally
  370. // unnessary! If the random number generate is 'seeded' with the
  371. // same starting value every time, it will generate the same sequence
  372. // of values every time. So the clock adjustment parameters for each
  373. // pixel are 'stored' in a pseudo-random number generator! The PRNG
  374. // is reset, and then the first numbers out of it are the clock
  375. // adjustment parameters for the first pixel, the second numbers out
  376. // of it are the parameters for the second pixel, and so on.
  377. // In this way, we can 'store' a stable sequence of thousands of
  378. // random clock adjustment parameters in literally two bytes of RAM.
  379. //
  380. // There's a little bit of fixed-point math involved in applying the
  381. // clock speed adjustments, which are expressed in eighths. Each pixel's
  382. // clock speed ranges from 8/8ths of the system clock (i.e. 1x) to
  383. // 23/8ths of the system clock (i.e. nearly 3x).
  384. //
  385. // On a basic Arduino Uno or Leonardo, this code can twinkle 300+ pixels
  386. // smoothly at over 50 updates per seond.
  387. //
  388. // -Mark Kriegsman, December 2015
  389.  
  390. // This function loops over each pixel, calculates the
  391. // adjusted 'clock' that this pixel should use, and calls
  392. // "CalculateOneTwinkle" on each pixel. It then displays
  393. // either the twinkle color of the background color,
  394. // whichever is brighter.
  395.  
  396. // Overall twinkle speed.
  397. // 0 (VERY slow) to 8 (VERY fast).
  398. // 4, 5, and 6 are recommended, default is 4.
  399. #define TWINKLE_SPEED 6 // 4
  400.  
  401. // Overall twinkle density.
  402. // 0 (NONE lit) to 8 (ALL lit at once).
  403. // Default is 5.
  404. #define TWINKLE_DENSITY 5
  405.  
  406.  
  407. // Background color for 'unlit' pixels
  408. // Can be set to CRGB::Black if desired.
  409. CRGB gBackgroundColor = CRGB::Black;
  410. // Example of dim incandescent fairy light background color
  411. //CRGB gBackgroundColor = CRGB(CRGB::FairyLight).nscale8_video(16);
  412.  
  413. // If AUTO_SELECT_BACKGROUND_COLOR is set to 1,
  414. // then for any palette where the first two entries
  415. // are the same, a dimmed version of that color will
  416. // automatically be used as the background color.
  417. #define AUTO_SELECT_BACKGROUND_COLOR 0
  418.  
  419. // If COOL_LIKE_INCANDESCENT is set to 1, colors will
  420. // fade out slighted 'reddened', similar to how
  421. // incandescent bulbs change color as they get dim down.
  422. #define COOL_LIKE_INCANDESCENT 1
  423.  
  424.  
  425.  
  426. void drawTwinkles()
  427. {
  428. // "PRNG16" is the pseudorandom number generator
  429. // It MUST be reset to the same starting value each time
  430. // this function is called, so that the sequence of 'random'
  431. // numbers that it generates is (paradoxically) stable.
  432. uint16_t PRNG16 = 11337;
  433.  
  434. uint32_t clock32 = millis();
  435.  
  436. // Set up the background color, "bg".
  437. // if AUTO_SELECT_BACKGROUND_COLOR == 1, and the first two colors of
  438. // the current palette are identical, then a deeply faded version of
  439. // that color is used for the background color
  440. CRGB bg;
  441. if( (AUTO_SELECT_BACKGROUND_COLOR == 1) &&
  442. (gCurrentPalette[0] == gCurrentPalette[1] )) {
  443. bg = gCurrentPalette[0];
  444. uint8_t bglight = bg.getAverageLight();
  445. if( bglight > 64) {
  446. bg.nscale8_video( 16); // very bright, so scale to 1/16th
  447. } else if( bglight > 16) {
  448. bg.nscale8_video( 64); // not that bright, so scale to 1/4th
  449. } else {
  450. bg.nscale8_video( 86); // dim, scale to 1/3rd.
  451. }
  452. } else {
  453. bg = gBackgroundColor; // just use the explicitly defined background color
  454. }
  455.  
  456. uint8_t backgroundBrightness = bg.getAverageLight();
  457.  
  458. for( CRGB& pixel: leds) {
  459. PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
  460. uint16_t myclockoffset16= PRNG16; // use that number as clock offset
  461. PRNG16 = (uint16_t)(PRNG16 * 2053) + 1384; // next 'random' number
  462. // use that number as clock speed adjustment factor (in 8ths, from 8/8ths to 23/8ths)
  463. uint8_t myspeedmultiplierQ5_3 = ((((PRNG16 & 0xFF)>>4) + (PRNG16 & 0x0F)) & 0x0F) + 0x08;
  464. uint32_t myclock30 = (uint32_t)((clock32 * myspeedmultiplierQ5_3) >> 3) + myclockoffset16;
  465. uint8_t myunique8 = PRNG16 >> 8; // get 'salt' value for this pixel
  466.  
  467. // We now have the adjusted 'clock' for this pixel, now we call
  468. // the function that computes what color the pixel should be based
  469. // on the "brightness = f( time )" idea.
  470. CRGB c = computeOneTwinkle( myclock30, myunique8);
  471.  
  472. uint8_t cbright = c.getAverageLight();
  473. int16_t deltabright = cbright - backgroundBrightness;
  474. if( deltabright >= 32 || (!bg)) {
  475. // If the new pixel is significantly brighter than the background color,
  476. // use the new color.
  477. pixel = c;
  478. } else if( deltabright > 0 ) {
  479. // If the new pixel is just slightly brighter than the background color,
  480. // mix a blend of the new color and the background color
  481. pixel = blend( bg, c, deltabright * 8);
  482. } else {
  483. // if the new pixel is not at all brighter than the background color,
  484. // just use the background color.
  485. pixel = bg;
  486. }
  487. }
  488. }
  489.  
  490.  
  491. // This function takes a time in pseudo-milliseconds,
  492. // figures out brightness = f( time ), and also hue = f( time )
  493. // The 'low digits' of the millisecond time are used as
  494. // input to the brightness wave function.
  495. // The 'high digits' are used to select a color, so that the color
  496. // does not change over the course of the fade-in, fade-out
  497. // of one cycle of the brightness wave function.
  498. // The 'high digits' are also used to determine whether this pixel
  499. // should light at all during this cycle, based on the TWINKLE_DENSITY.
  500. CRGB computeOneTwinkle( uint32_t ms, uint8_t salt)
  501. {
  502. uint16_t ticks = ms >> (8-TWINKLE_SPEED);
  503. uint8_t fastcycle8 = ticks;
  504. uint16_t slowcycle16 = (ticks >> 8) + salt;
  505. slowcycle16 += sin8( slowcycle16);
  506. slowcycle16 = (slowcycle16 * 2053) + 1384;
  507. uint8_t slowcycle8 = (slowcycle16 & 0xFF) + (slowcycle16 >> 8);
  508.  
  509. uint8_t bright = 0;
  510. if( ((slowcycle8 & 0x0E)/2) < TWINKLE_DENSITY) {
  511. bright = attackDecayWave8( fastcycle8);
  512. }
  513.  
  514. uint8_t hue = slowcycle8 - salt;
  515. CRGB c;
  516. if( bright > 0) {
  517. c = ColorFromPalette( gCurrentPalette, hue, bright, NOBLEND);
  518. if( COOL_LIKE_INCANDESCENT == 1 ) {
  519. coolLikeIncandescent( c, fastcycle8);
  520. }
  521. } else {
  522. c = CRGB::Black;
  523. }
  524. return c;
  525. }
  526.  
  527.  
  528. // This function is like 'triwave8', which produces a
  529. // symmetrical up-and-down triangle sawtooth waveform, except that this
  530. // function produces a triangle wave with a faster attack and a slower decay:
  531. //
  532. // / \
  533. // / \
  534. // / \
  535. // / \
  536. //
  537.  
  538. uint8_t attackDecayWave8( uint8_t i)
  539. {
  540. if( i < 86) {
  541. return i * 3;
  542. } else {
  543. i -= 86;
  544. return 255 - (i + (i/2));
  545. }
  546. }
  547.  
  548. // This function takes a pixel, and if its in the 'fading down'
  549. // part of the cycle, it adjusts the color a little bit like the
  550. // way that incandescent bulbs fade toward 'red' as they dim.
  551. void coolLikeIncandescent( CRGB& c, uint8_t phase)
  552. {
  553. if( phase < 128) return;
  554.  
  555. uint8_t cooling = (phase - 128) >> 4;
  556. c.g = qsub8( c.g, cooling);
  557. c.b = qsub8( c.b, cooling * 2);
  558. }
  559.  
  560. // A mostly red palette with green accents and white trim.
  561. // "CRGB::Gray" is used as white to keep the brightness more uniform.
  562. const TProgmemRGBPalette16 RedGreenWhite_p FL_PROGMEM =
  563. { CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
  564. CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
  565. CRGB::Red, CRGB::Red, CRGB::Gray, CRGB::Gray,
  566. CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green };
  567.  
  568. // A mostly (dark) green palette with red berries.
  569. #define Holly_Green 0x00580c
  570. #define Holly_Red 0xB00402
  571. const TProgmemRGBPalette16 Holly_p FL_PROGMEM =
  572. { Holly_Green, Holly_Green, Holly_Green, Holly_Green,
  573. Holly_Green, Holly_Green, Holly_Green, Holly_Green,
  574. Holly_Green, Holly_Green, Holly_Green, Holly_Green,
  575. Holly_Green, Holly_Green, Holly_Green, Holly_Red
  576. };
  577.  
  578. // A red and white striped palette
  579. // "CRGB::Gray" is used as white to keep the brightness more uniform.
  580. const TProgmemRGBPalette16 RedWhite_p FL_PROGMEM =
  581. { CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
  582. CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray,
  583. CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
  584. CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray };
  585.  
  586. // A mostly blue palette with white accents.
  587. // "CRGB::Gray" is used as white to keep the brightness more uniform.
  588. const TProgmemRGBPalette16 BlueWhite_p FL_PROGMEM =
  589. { CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
  590. CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
  591. CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
  592. CRGB::Blue, CRGB::Gray, CRGB::Gray, CRGB::Gray };
  593.  
  594. // A pure "fairy light" palette with some brightness variations
  595. #define HALFFAIRY ((CRGB::FairyLight & 0xFEFEFE) / 2)
  596. #define QUARTERFAIRY ((CRGB::FairyLight & 0xFCFCFC) / 4)
  597. const TProgmemRGBPalette16 FairyLight_p FL_PROGMEM =
  598. { CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight,
  599. HALFFAIRY, HALFFAIRY, CRGB::FairyLight, CRGB::FairyLight,
  600. QUARTERFAIRY, QUARTERFAIRY, CRGB::FairyLight, CRGB::FairyLight,
  601. CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight, CRGB::FairyLight };
  602.  
  603. // A palette of soft snowflakes with the occasional bright one
  604. const TProgmemRGBPalette16 Snow_p FL_PROGMEM =
  605. { 0x304048, 0x304048, 0x304048, 0x304048,
  606. 0x304048, 0x304048, 0x304048, 0x304048,
  607. 0x304048, 0x304048, 0x304048, 0x304048,
  608. 0x304048, 0x304048, 0x304048, 0xE0F0FF };
  609.  
  610. // A palette reminiscent of large 'old-school' C9-size tree lights
  611. // in the five classic colors: red, orange, green, blue, and white.
  612. #define C9_Red 0xB80400
  613. #define C9_Orange 0x902C02
  614. #define C9_Green 0x046002
  615. #define C9_Blue 0x070758
  616. #define C9_White 0x606820
  617. const TProgmemRGBPalette16 RetroC9_p FL_PROGMEM =
  618. { C9_Red, C9_Orange, C9_Red, C9_Orange,
  619. C9_Orange, C9_Red, C9_Orange, C9_Red,
  620. C9_Green, C9_Green, C9_Green, C9_Green,
  621. C9_Blue, C9_Blue, C9_Blue,
  622. C9_White
  623. };
  624.  
  625. // A cold, icy pale blue palette
  626. #define Ice_Blue1 0x0C1040
  627. #define Ice_Blue2 0x182080
  628. #define Ice_Blue3 0x5080C0
  629. const TProgmemRGBPalette16 Ice_p FL_PROGMEM =
  630. {
  631. Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
  632. Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
  633. Ice_Blue1, Ice_Blue1, Ice_Blue1, Ice_Blue1,
  634. Ice_Blue2, Ice_Blue2, Ice_Blue2, Ice_Blue3
  635. };
  636.  
  637.  
  638. // Add or remove palette names from this list to control which color
  639. // palettes are used, and in what order.
  640. const TProgmemRGBPalette16* ActivePaletteList[] = {
  641. &RetroC9_p,
  642. &BlueWhite_p,
  643. &RainbowColors_p,
  644. &FairyLight_p,
  645. &RedGreenWhite_p,
  646. &PartyColors_p,
  647. &RedWhite_p,
  648. &Snow_p,
  649. &Holly_p,
  650. &Ice_p
  651. };
  652.  
  653.  
  654. // Advance to the next color palette in the list (above).
  655. void chooseNextColorPalette( CRGBPalette16& pal)
  656. {
  657. const uint8_t numberOfPalettes = sizeof(ActivePaletteList) / sizeof(ActivePaletteList[0]);
  658. static uint8_t whichPalette = -1;
  659. whichPalette = addmod8( whichPalette, 1, numberOfPalettes);
  660.  
  661. pal = *(ActivePaletteList[whichPalette]);
  662. }
  663.  
  664.  
  665. // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement