Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FastLED Blink
- *
- * By: Andrew Tuline
- * Date: Nov 29, 2019
- *
- *
- * A couple of different methods to blink all the LED's.
- * One is simple and uses delay statements, but to the detriment of the loop speed.
- * The other doesn't use delay statements and is great if you want to add inputs, such as polled buttons.
- *
- */
- #include <FastLED.h>
- #define LED_TYPE WS2812B
- #define COLOUR_ORDER GRB
- #define NUM_LEDS 10
- #define DATA_PIN D5
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness(150);
- } // setup()
- void loop() {
- // method1(); // Using delay statements. Ugh!
- method2(); // High speed because NO delay statements.
- } // loop()
- void method1() { // This method uses delay statements and is horrible if you want to use buttons.
- fill_solid(leds,NUM_LEDS,0x642a00);
- FastLED.show();
- delay(250);
- FastLED.clear();
- FastLED.show();
- delay(250);
- } // method1()
- void method2() { // This method is great if you want to add input buttons.
- bool myBin = (millis()/4 % 255 > 128); // 0 or 1 comparison operator with 50% PWM.
- long myVal = (!myBin) ? 0 : 0x642a00; // ternary operator
- fill_solid(leds, NUM_LEDS, myVal);
- FastLED.show();
- } // method2()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement