Advertisement
atuline

FastLED blink

Nov 29th, 2019
1,517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /* FastLED Blink
  2. *
  3. * By: Andrew Tuline
  4. * Date: Nov 29, 2019
  5. *
  6. *
  7. * A couple of different methods to blink all the LED's.
  8. * One is simple and uses delay statements, but to the detriment of the loop speed.
  9. * The other doesn't use delay statements and is great if you want to add inputs, such as polled buttons.
  10. *
  11. */
  12.  
  13. #include <FastLED.h>
  14.  
  15. #define LED_TYPE WS2812B
  16. #define COLOUR_ORDER GRB
  17. #define NUM_LEDS 10
  18. #define DATA_PIN D5
  19.  
  20. CRGB leds[NUM_LEDS];
  21.  
  22.  
  23.  
  24. void setup() {
  25.  
  26. FastLED.addLeds<LED_TYPE, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS);
  27. FastLED.setBrightness(150);
  28.  
  29. } // setup()
  30.  
  31.  
  32.  
  33. void loop() {
  34.  
  35. // method1(); // Using delay statements. Ugh!
  36. method2(); // High speed because NO delay statements.
  37.  
  38. } // loop()
  39.  
  40.  
  41.  
  42. void method1() { // This method uses delay statements and is horrible if you want to use buttons.
  43.  
  44. fill_solid(leds,NUM_LEDS,0x642a00);
  45. FastLED.show();
  46. delay(250);
  47.  
  48. FastLED.clear();
  49. FastLED.show();
  50. delay(250);
  51.  
  52. } // method1()
  53.  
  54.  
  55.  
  56. void method2() { // This method is great if you want to add input buttons.
  57.  
  58. bool myBin = (millis()/4 % 255 > 128); // 0 or 1 comparison operator with 50% PWM.
  59. long myVal = (!myBin) ? 0 : 0x642a00; // ternary operator
  60. fill_solid(leds, NUM_LEDS, myVal);
  61. FastLED.show();
  62.  
  63. } // method2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement