Advertisement
Guest User

sketch aurora borealis

a guest
Oct 4th, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include "FastLED.h"
  5.  
  6.  
  7. #if FASTLED_VERSION < 3001000
  8. #error "Requires FastLED 3.1 or later; check github for latest code."
  9. #endif
  10.  
  11. #define DATA_PIN 3
  12. //#define CLK_PIN 4
  13. #define LED_TYPE WS2811
  14. #define COLOR_ORDER GRB
  15. #define NUM_LEDS 9
  16.  
  17. #define BRIGHTNESS 255
  18.  
  19. CRGB leds[NUM_LEDS];
  20.  
  21. // ten seconds per color palette makes a good demo
  22. // 20-120 is better for deployment
  23. #define SECONDS_PER_PALETTE 33
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. void setup() {
  31. delay(9000); // 3 second delay for recovery
  32.  
  33. // tell FastLED about the LED strip configuration
  34. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS)
  35. //.setCorrection(TypicalLEDStrip) // cpt-city palettes have different color balance
  36. .setDither(BRIGHTNESS < 255);
  37.  
  38. // set master brightness control
  39. FastLED.setBrightness(BRIGHTNESS);
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. // Forward declarations of an array of cpt-city gradient palettes, and
  48. // a count of how many there are. The actual color palette definitions
  49. // are at the bottom of this file.
  50. extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
  51. extern const uint8_t gGradientPaletteCount;
  52.  
  53. // Current palette number from the 'playlist' of color palettes
  54. uint8_t gCurrentPaletteNumber = 0;
  55.  
  56. CRGBPalette16 gCurrentPalette( CRGB::Black);
  57. CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. void loop()
  68. {
  69. EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
  70. gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount);
  71. gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ];
  72. }
  73.  
  74. EVERY_N_MILLISECONDS(40) {
  75. nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16);
  76. }
  77.  
  78. colorwaves( leds, NUM_LEDS, gCurrentPalette);
  79.  
  80. FastLED.show();
  81. FastLED.delay(20);
  82. }
  83.  
  84.  
  85.  
  86.  
  87. // This function draws color waves with an ever-changing,
  88. // widely-varying set of parameters, using a color palette.
  89. void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette)
  90. {
  91. static uint16_t sPseudotime = 0;
  92. static uint16_t sLastMillis = 0;
  93. static uint16_t sHue16 = 0;
  94.  
  95. uint8_t sat8 = beatsin88( 87, 220, 250);
  96. uint8_t brightdepth = beatsin88( 341, 96, 224);
  97. uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
  98. uint8_t msmultiplier = beatsin88(147, 23, 60);
  99.  
  100. uint16_t hue16 = sHue16;//gHue * 256;
  101. uint16_t hueinc16 = beatsin88(113, 300, 1500);
  102.  
  103. uint16_t ms = millis();
  104. uint16_t deltams = ms - sLastMillis ;
  105. sLastMillis = ms;
  106. sPseudotime += deltams * msmultiplier;
  107. sHue16 += deltams * beatsin88( 400, 5,9);
  108. uint16_t brightnesstheta16 = sPseudotime;
  109.  
  110. for( uint16_t i = 0 ; i < numleds; i++) {
  111. hue16 += hueinc16;
  112. uint8_t hue8 = hue16 / 256;
  113. uint16_t h16_128 = hue16 >> 7;
  114. if( h16_128 & 0x100) {
  115. hue8 = 255 - (h16_128 >> 1);
  116. } else {
  117. hue8 = h16_128 >> 1;
  118. }
  119.  
  120. brightnesstheta16 += brightnessthetainc16;
  121. uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
  122.  
  123. uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
  124. uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
  125. bri8 += (255 - brightdepth);
  126.  
  127. uint8_t index = hue8;
  128. //index = triwave8( index);
  129. index = scale8( index, 240);
  130.  
  131. CRGB newcolor = ColorFromPalette( palette, index, bri8);
  132.  
  133. uint16_t pixelnumber = i;
  134. pixelnumber = (numleds-1) - pixelnumber;
  135.  
  136. nblend( ledarray[pixelnumber], newcolor, 128);
  137. }
  138. }
  139.  
  140.  
  141.  
  142. // Alternate rendering function just scrolls the current palette
  143. // across the defined LED strip.
  144. void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette)
  145. {
  146. static uint8_t startindex = 0;
  147. startindex--;
  148. fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
  149. }
  150.  
  151. // erst ab hier die palette knife ??? //
  152.  
  153.  
  154. // Gradient Color Palette definitions for 33 different cpt-city color palettes.
  155. // 956 bytes of PROGMEM for all of the palettes together,
  156. // +618 bytes of PROGMEM for gradient palette code (AVR).
  157. // 1,494 bytes total for all 34 color palettes and associated code.
  158.  
  159.  
  160. // Gradient palette "bar_sinestre_gp", originally from
  161. // http://soliton.vm.bytemark.co.uk/pub/cpt-city/pj/1/tn/bar-sinestre.png.index.html
  162. // converted for FastLED with gammas (2.6, 2.2, 2.5)
  163. // Size: 60 bytes of program space.
  164.  
  165. DEFINE_GRADIENT_PALETTE( bar_sinestre_gp ) {
  166. 0, 46, 37, 5,
  167. 0, 46, 37, 5,
  168. 12, 27, 26, 3,
  169. 30, 1, 8, 4,
  170. 43, 1, 15, 9,
  171. 73, 7, 68, 29,
  172. 94, 22, 87, 15,
  173. 119, 1, 37, 29,
  174. 137, 1, 50, 62,
  175. 163, 4, 68,153,
  176. 181, 4, 68,153,
  177. 198, 1, 29, 34,
  178. 224, 18, 45, 5,
  179. 237, 1, 17, 19,
  180. 255, 46, 37, 5};
  181.  
  182.  
  183.  
  184. // This list of color palettes acts as a "playlist"; you can
  185. // add or delete, or re-arrange as you wish.
  186. const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
  187. bar_sinestre_gp,
  188. };
  189.  
  190. // Count of how many cpt-city gradients are defined:
  191. const uint8_t gGradientPaletteCount =
  192. sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement