Advertisement
talofer99

addressable_randomRGB

May 23rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. // include library
  2. #include<FastLED.h>
  3.  
  4. //define number of LED and pin
  5. #define NUM_LEDS 8
  6. #define DATA_PIN 3
  7.  
  8. // create the ld object array
  9. CRGB leds[NUM_LEDS];
  10.  
  11. // define 3 byte for the random color
  12. byte  r, g, b;
  13.  
  14. void setup() {
  15.   // init the LED object
  16.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  17.   // set random seed
  18.   randomSeed(analogRead(0));
  19. }
  20.  
  21.  
  22. void loop() {
  23.   // loop over the NUM_LEDS
  24.   for (int cur = 0; cur < NUM_LEDS; cur++) {
  25.     // chose random value for the r/g/b
  26.     r = random(0, 255);
  27.     g = random(0, 255);
  28.     b = random(0, 255);
  29.    
  30.     //set the value to the led
  31.     leds[cur] = CRGB (r, g, b);
  32.   }
  33.   // set the colors set into the phisical LED
  34.   FastLED.show();
  35.  
  36.   // delay 50 millis
  37.   FastLED.delay(50);
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement