Advertisement
GyroGearloose

FastLED DemoReel for APA104 RGB+W

Jun 2nd, 2016
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.36 KB | None | 0 0
  1. /*
  2.  Mark Kriegsman's DemoReel 100 modified for APA104 RGB+W LEDs.
  3.  This is the first humble attempt to use RGBW LEDs with FastLED.
  4.  
  5.  APA104 are 'improved' WS2812B, so this LED_TYPE can be chosen as well.
  6.  The strip is set up with alternating Color and White LEDs.
  7.  http://www.szledcolor.com.img.800cdn.com/upload/2015423162708_1.jpg
  8.  To make things easier the White LEDs have also an 3 x 8 bit internal
  9.  register and behave like normal color APA104, just with the difference
  10.  that there are 768 brightness steps for the white LED.
  11.  
  12.  In order to address following them arrays were defined
  13.  CRGB leds_Color[NUM_LEDS];
  14.  CRGB leds_White[NUM_LEDS];
  15.  To fill them with the right odd and even numbers Daniel Garcia
  16.  contibuted this formula to allow the special FastLED functions.
  17.  for(int i = 0; i < (NUM_LEDS/2); i++) { leds[i*2] = leds_Color[i]; leds[(i*2)+1] = leds_White[i]; }
  18.  The function is executed in beginning of the loop.
  19.  
  20.  For optional plain access the arrays can be defined as
  21.  uint8_t Array_Color[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142};
  22.  uint8_t Array_White[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143};
  23.  
  24.  For longer strips you find at the bottom of the sketch even and odd numbers from 0 .. 1000
  25.  
  26.  Gyro Gearloose
  27.  June 2016
  28. */
  29.  
  30. #include "FastLED.h"
  31. FASTLED_USING_NAMESPACE
  32.  
  33. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  34. #warning "Requires FastLED 3.1 or later; check github for latest code."
  35. #endif
  36.  
  37. #define DATA_PIN    12
  38. //#define CLK_PIN   4
  39. //#define LED_TYPE    APA104
  40. #define LED_TYPE    WS2812B
  41. #define COLOR_ORDER GRB
  42. #define NUM_LEDS    144
  43. CRGB leds[NUM_LEDS];
  44. CRGB leds_Color[NUM_LEDS];
  45. CRGB leds_White[NUM_LEDS];
  46.  
  47. uint8_t Array_Color[] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142};
  48. uint8_t Array_White[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143};
  49.  
  50. #define BRIGHTNESS          96
  51. #define FRAMES_PER_SECOND  120
  52.  
  53. void setup() {
  54.   delay(3000); // 3 second delay for recovery
  55.  
  56.   // tell FastLED about the LED strip configuration
  57.   FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  58.   //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  59.  
  60.   // set master brightness control
  61.   FastLED.setBrightness(BRIGHTNESS);
  62. //for(int i = 0; i < (NUM_LEDS/2); i++) { leds[i*2] = leds_Color[i]; leds[(i*2)+1] = leds_White[i]; }
  63. Serial.begin(9600);
  64. }
  65.  
  66. // List of patterns to cycle through.  Each is defined as a separate function below.
  67. typedef void (*SimplePatternList[])();
  68. SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, /*juggle,*/ bpm };
  69.  
  70. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  71. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  72.  
  73. void loop()
  74. {
  75. for(int i = 0; i < (NUM_LEDS/2); i++) { leds[i*2] = leds_Color[i]; leds[(i*2)+1] = leds_White[i]; }
  76.   // Call the current pattern function once, updating the 'leds' array
  77.   gPatterns[gCurrentPatternNumber]();
  78.  
  79.   // send the 'leds' array out to the actual LED strip
  80.   FastLED.show();  
  81.   // insert a delay to keep the framerate modest
  82.   FastLED.delay(1000/FRAMES_PER_SECOND);
  83.  
  84.   // do some periodic updates
  85.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  86.   EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  87. }
  88.  
  89. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  90.  
  91. void nextPattern()
  92. {
  93.   // add one to the current pattern number, and wrap around at the end
  94.   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  95. }
  96.  
  97. void rainbow()
  98. {
  99.   // FastLED's built-in rainbow generator
  100. //for(int i = 0; i < (NUM_LEDS/2); i++) { leds[i*2] = leds_Color[i]; /*leds[(i*2)+1] = leds_White[i];*/ }
  101.   fill_rainbow( leds_Color, NUM_LEDS, gHue, 7);
  102. }
  103.  
  104. void rainbowWithGlitter()
  105. {
  106.   // built-in FastLED rainbow, plus some random sparkly glitter
  107.   rainbow();
  108.   addGlitter(80);
  109. }
  110.  
  111. void addGlitter( fract8 chanceOfGlitter)
  112. {
  113.   if( random8() < chanceOfGlitter) {
  114.     leds_Color[ random16(NUM_LEDS) ] += CRGB::White;
  115. //    leds_White[ random16(NUM_LEDS) ] += CRGB::White;
  116. //    fadeToBlackBy( leds_White, NUM_LEDS, 10);
  117.   }
  118. }
  119.  
  120. void confetti()
  121. {
  122.   // random colored speckles that blink in and fade smoothly
  123.   fadeToBlackBy( leds_Color, NUM_LEDS, 10);
  124.   int pos = random16(NUM_LEDS);
  125.   leds_Color[pos] += CHSV( gHue + random8(64), 200, 255);
  126. }
  127.  
  128. void sinelon()
  129. {
  130.   // a colored dot sweeping back and forth, with fading trails
  131.   fadeToBlackBy( leds_Color, NUM_LEDS/2, 20);
  132.   int pos = beatsin16(13,0,NUM_LEDS/2);
  133.   leds_Color[pos] += CHSV( gHue, 255, 192);
  134. }
  135.  
  136. void bpm()
  137. {
  138.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  139.   uint8_t BeatsPerMinute = 62;
  140.   CRGBPalette16 palette = PartyColors_p;
  141.   uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  142.   for( int i = 0; i < NUM_LEDS/2; i++) { //9948
  143.     leds_Color[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  144.   }
  145. }
  146.  
  147. void juggle() {  //looks strange
  148.   // eight colored dots, weaving in and out of sync with each other
  149.   fadeToBlackBy( leds, NUM_LEDS, 20);
  150.   byte dothue = 0;
  151.   for( int i = 0; i < 8; i++) {
  152.     leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  153.     dothue += 32;
  154.   }
  155. }
  156.  
  157. /*
  158. // even numbers 0..1000
  159. 2,4,6,8,10,12,14,16,18,
  160. 20,22,24,26,28,30,32,34,36,
  161. 38,40,42,44,46,48,50,52,54,
  162. 56,58,60,62,64,66,68,70,72,
  163. 74,76,78,80,82,84,86,88,90,
  164. 92,94,96,98,100,102,104,106,108,
  165. 110,112,114,116,118,120,122,124,126,
  166. 128,130,132,134,136,138,140,142,144,
  167.  
  168. 146,148,150,152,154,156,158,160,162,
  169. 164,166,168,170,172,174,176,178,180,
  170. 182,184,186,188,190,192,194,196,198,
  171. 200,202,204,206,208,210,212,214,216,
  172. 218,220,222,224,226,228,230,232,234,
  173. 236,238,240,242,244,246,248,250,252,
  174. 254,256,258,260,262,264,266,268,270,
  175. 272,274,276,278,280,282,284,286,288,
  176.  
  177. 290,292,294,296,298,300,302,304,306,
  178. 308,310,312,314,316,318,320,322,324,
  179. 326,328,330,332,334,336,338,340,342,
  180. 344,346,348,350,352,354,356,358,360,
  181. 362,364,366,368,370,372,374,376,378,
  182. 380,382,384,386,388,390,392,394,396,
  183. 398,400,402,404,406,408,410,412,414,
  184. 416,418,420,422,424,426,428,430,432,
  185. 434,436,438,440,442,444,446,448,450,
  186. 452,454,456,458,460,462,464,466,468,
  187. 470,472,474,476,478,480,482,484,486,
  188. 488,490,492,494,496,498,500,502,504,
  189. 506,508,510,512,514,516,518,520,522,
  190. 524,526,528,530,532,534,536,538,540,
  191. 542,544,546,548,550,552,554,556,558,
  192. 560,562,564,566,568,570,572,574,576,
  193. 578,580,582,584,586,588,590,592,594,
  194. 596,598,600,602,604,606,608,610,612,
  195. 614,616,618,620,622,624,626,628,630,
  196. 632,634,636,638,640,642,644,646,648,
  197. 650,652,654,656,658,660,662,664,666,
  198. 668,670,672,674,676,678,680,682,684,
  199. 686,688,690,692,694,696,698,700,702,
  200. 704,706,708,710,712,714,716,718,720,
  201. 722,724,726,728,730,732,734,736,738,
  202. 740,742,744,746,748,750,752,754,756,
  203. 758,760,762,764,766,768,770,772,774,
  204. 776,778,780,782,784,786,788,790,792,
  205. 794,796,798,800,802,804,806,808,810,
  206. 812,814,816,818,820,822,824,826,828,
  207. 830,832,834,836,838,840,842,844,846,
  208. 848,850,852,854,856,858,860,862,864,
  209. 866,868,870,872,874,876,878,880,882,
  210. 884,886,888,890,892,894,896,898,900,
  211. 902,904,906,908,910,912,914,916,918,
  212. 920,922,924,926,928,930,932,934,936,
  213. 938,940,942,944,946,948,950,952,954,
  214. 956,958,960,962,964,966,968,970,972,
  215. 974,976,978,980,982,984,986,988,990,
  216. 992,994,996,998,1000
  217.  
  218. // odd numbers 0..1000
  219. 1,3,5,7,9,11,13,15,17,19,
  220. 21,23,25,27,29,31,33,35,37,
  221. 39,41,43,45,47,49,51,53,55,
  222. 57,59,61,63,65,67,69,71,73,
  223. 75,77,79,81,83,85,87,89,91,
  224. 93,95,97,99,101,103,105,107,109,
  225. 111,113,115,117,119,121,123,125,127,
  226. 129,131,133,135,137,139,141,143,
  227.  
  228. 145,
  229. 147,149,151,153,155,157,159,161,163,
  230. 165,167,169,171,173,175,177,179,181,
  231. 183,185,187,189,191,193,195,197,199,
  232. 201,203,205,207,209,211,213,215,217,
  233. 219,221,223,225,227,229,231,233,235,
  234. 237,239,241,243,245,247,249,251,253,
  235. 255,257,259,261,263,265,267,269,271,
  236. 273,275,277,279,281,283,285,287,
  237.  
  238. 289,
  239. 291,293,295,297,299,301,303,305,307,
  240. 309,311,313,315,317,319,321,323,325,
  241. 327,329,331,333,335,337,339,341,343,
  242. 345,347,349,351,353,355,357,359,361,
  243. 363,365,367,369,371,373,375,377,379,
  244. 381,383,385,387,389,391,393,395,397,
  245. 399,401,403,405,407,409,411,413,415,
  246. 417,419,421,423,425,427,429,431,433,
  247. 435,437,439,441,443,445,447,449,451,
  248. 453,455,457,459,461,463,465,467,469,
  249. 471,473,475,477,479,481,483,485,487,
  250. 489,491,493,495,497,499,501,503,505,
  251. 507,509,511,513,515,517,519,521,523,
  252. 525,527,529,531,533,535,537,539,541,
  253. 543,545,547,549,551,553,555,557,559,
  254. 561,563,565,567,569,571,573,575,577,
  255. 579,581,583,585,587,589,591,593,595,
  256. 597,599,601,603,605,607,609,611,613,
  257. 615,617,619,621,623,625,627,629,631,
  258. 633,635,637,639,641,643,645,647,649,
  259. 651,653,655,657,659,661,663,665,667,
  260. 669,671,673,675,677,679,681,683,685,
  261. 687,689,691,693,695,697,699,701,703,
  262. 705,707,709,711,713,715,717,719,721,
  263. 723,725,727,729,731,733,735,737,739,
  264. 741,743,745,747,749,751,753,755,757,
  265. 759,761,763,765,767,769,771,773,775,
  266. 777,779,781,783,785,787,789,791,793,
  267. 795,797,799,801,803,805,807,809,811,
  268. 813,815,817,819,821,823,825,827,829,
  269. 831,833,835,837,839,841,843,845,847,
  270. 849,851,853,855,857,859,861,863,865,
  271. 867,869,871,873,875,877,879,881,883,
  272. 885,887,889,891,893,895,897,899,901,
  273. 903,905,907,909,911,913,915,917,919,
  274. 921,923,925,927,929,931,933,935,937,
  275. 939,941,943,945,947,949,951,953,955,
  276. 957,959,961,963,965,967,969,971,973,
  277. 975,977,979,981,983,985,987,989,991,
  278. 993,995,997,999
  279.  
  280. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement