Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Turn signal
- *
- * By: Andrew Tuline
- * Date: Nov 29, 2019
- *
- * To re-create a turn signal, both with delay based code (ugh), as well as non-delay based code. If you want to use buttons, you need to get rid of those delays.
- *
- */
- #include <FastLED.h>
- #define LED_TYPE WS2812B //TYPE OF LED
- #define COLOUR_ORDER GRB //SEQUENCA OF DATA STREAM
- #define NUM_LEDS 10 // Number of LEDS
- #define DATA_PIN D5 // D8 D1 mini
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS); // for GRB LEDs
- FastLED.setBrightness(150);
- } // setup()
- void loop() {
- // method1();
- method2();
- } // loop()
- void method1() { // This uses delays and is nice and simple to understand for beginners.
- for(int i=0;i<NUM_LEDS;i++){
- leds[i].setRGB(100,42,0);
- FastLED.show();
- delay(50); }
- for(int i=0;i<NUM_LEDS;i++){
- leds[i].setRGB(0,0,0);
- FastLED.show();
- delay(50); }
- }
- void method2() { // This doesn't use delays, but takes a bit more thought.
- int myNum = (millis() / 50) % 20; // Realtime counter from 0 to 19 (or 2 * NUM_LEDS).
- leds[myNum %10] = (myNum < 10) ? 0 : 0x642a00; // Assigns value to leds of 0 through 9 and if myNUM > 9, then give it a colour.
- FastLED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement