Guest User

button_cycle_test.ino

a guest
Mar 5th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. FASTLED_USING_NAMESPACE
  4.  
  5. #define DATA_PIN 0
  6. #define LED_TYPE WS2812B
  7. #define COLOR_ORDER GRB
  8. #define NUM_LEDS 23
  9. CRGB leds[NUM_LEDS];
  10.  
  11. #define BRIGHTNESS 96
  12. #define FRAMES_PER_SECOND 120
  13.  
  14. void setup(){
  15. delay(3000);
  16. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  17. FastLED.setBrightness(BRIGHTNESS);
  18. }
  19.  
  20. // List of patterns to cycle through. Each is defined as a separate function below.
  21. typedef void (*SimplePatternList[])();
  22. SimplePatternList gPatterns = {
  23. rainbow,
  24. rainbowWithGlitter,
  25. confetti,
  26. sinelon,
  27. juggle,
  28. bpm
  29. };
  30.  
  31. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  32. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  33.  
  34. void loop(){
  35. // Call the current pattern function once, updating the 'leds' array
  36. gPatterns[gCurrentPatternNumber]();
  37.  
  38. FastLED.show();
  39. EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  40. }
  41.  
  42. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  43.  
  44.  
  45. void nextPattern()
  46. {
  47. // add one to the current pattern number, and wrap around at the end
  48. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  49. }
  50.  
  51. void rainbow()
  52. {
  53. // FastLED's built-in rainbow generator
  54. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  55. }
  56.  
  57. void rainbowWithGlitter()
  58. {
  59. // built-in FastLED rainbow, plus some random sparkly glitter
  60. rainbow();
  61. addGlitter(80);
  62. }
  63.  
  64. void addGlitter( fract8 chanceOfGlitter)
  65. {
  66. if( random8() < chanceOfGlitter) {
  67. leds[ random16(NUM_LEDS) ] += CRGB::White;
  68. }
  69. }
  70.  
  71. void confetti()
  72. {
  73. // random colored speckles that blink in and fade smoothly
  74. fadeToBlackBy( leds, NUM_LEDS, 10);
  75. int pos = random16(NUM_LEDS);
  76. leds[pos] += CHSV( gHue + random8(64), 200, 255);
  77. }
  78.  
  79. void sinelon()
  80. {
  81. // a colored dot sweeping back and forth, with fading trails
  82. fadeToBlackBy( leds, NUM_LEDS, 20);
  83. int pos = beatsin16(13,0,NUM_LEDS);
  84. leds[pos] += CHSV( gHue, 255, 192);
  85. }
  86.  
  87. void bpm()
  88. {
  89. // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  90. uint8_t BeatsPerMinute = 62;
  91. CRGBPalette16 palette = PartyColors_p;
  92. uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  93. for( int i = 0; i < NUM_LEDS; i++) { //9948
  94. leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  95. }
  96. }
  97.  
  98. void juggle() {
  99. // eight colored dots, weaving in and out of sync with each other
  100. fadeToBlackBy( leds, NUM_LEDS, 20);
  101. byte dothue = 0;
  102. for( int i = 0; i < 8; i++) {
  103. leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  104. dothue += 32;
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment