PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DemoReel100.ino 3.5KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include <FastLED.h>
  2. FASTLED_USING_NAMESPACE
  3. // FastLED "100-lines-of-code" demo reel, showing just a few
  4. // of the kinds of animation patterns you can quickly and easily
  5. // compose using FastLED.
  6. //
  7. // This example also shows one easy way to define multiple
  8. // animations patterns and have them automatically rotate.
  9. //
  10. // -Mark Kriegsman, December 2014
  11. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  12. #warning "Requires FastLED 3.1 or later; check github for latest code."
  13. #endif
  14. #define DATA_PIN 3
  15. //#define CLK_PIN 4
  16. #define LED_TYPE WS2811
  17. #define COLOR_ORDER GRB
  18. #define NUM_LEDS 64
  19. CRGB leds[NUM_LEDS];
  20. #define BRIGHTNESS 96
  21. #define FRAMES_PER_SECOND 120
  22. void setup() {
  23. delay(3000); // 3 second delay for recovery
  24. // tell FastLED about the LED strip configuration
  25. FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  26. //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  27. // set master brightness control
  28. FastLED.setBrightness(BRIGHTNESS);
  29. }
  30. // List of patterns to cycle through. Each is defined as a separate function below.
  31. typedef void (*SimplePatternList[])();
  32. SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };
  33. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  34. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  35. void loop()
  36. {
  37. // Call the current pattern function once, updating the 'leds' array
  38. gPatterns[gCurrentPatternNumber]();
  39. // send the 'leds' array out to the actual LED strip
  40. FastLED.show();
  41. // insert a delay to keep the framerate modest
  42. FastLED.delay(1000/FRAMES_PER_SECOND);
  43. // do some periodic updates
  44. EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  45. EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  46. }
  47. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  48. void nextPattern()
  49. {
  50. // add one to the current pattern number, and wrap around at the end
  51. gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  52. }
  53. void rainbow()
  54. {
  55. // FastLED's built-in rainbow generator
  56. fill_rainbow( leds, NUM_LEDS, gHue, 7);
  57. }
  58. void rainbowWithGlitter()
  59. {
  60. // built-in FastLED rainbow, plus some random sparkly glitter
  61. rainbow();
  62. addGlitter(80);
  63. }
  64. void addGlitter( fract8 chanceOfGlitter)
  65. {
  66. if( random8() < chanceOfGlitter) {
  67. leds[ random16(NUM_LEDS) ] += CRGB::White;
  68. }
  69. }
  70. void confetti()
  71. {
  72. // random colored speckles that blink in and fade smoothly
  73. fadeToBlackBy( leds, NUM_LEDS, 10);
  74. int pos = random16(NUM_LEDS);
  75. leds[pos] += CHSV( gHue + random8(64), 200, 255);
  76. }
  77. void sinelon()
  78. {
  79. // a colored dot sweeping back and forth, with fading trails
  80. fadeToBlackBy( leds, NUM_LEDS, 20);
  81. int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  82. leds[pos] += CHSV( gHue, 255, 192);
  83. }
  84. void bpm()
  85. {
  86. // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  87. uint8_t BeatsPerMinute = 62;
  88. CRGBPalette16 palette = PartyColors_p;
  89. uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  90. for( int i = 0; i < NUM_LEDS; i++) { //9948
  91. leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  92. }
  93. }
  94. void juggle() {
  95. // eight colored dots, weaving in and out of sync with each other
  96. fadeToBlackBy( leds, NUM_LEDS, 20);
  97. byte dothue = 0;
  98. for( int i = 0; i < 8; i++) {
  99. leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  100. dothue += 32;
  101. }
  102. }