talofer99

Big_Ben_Led_Example

Jul 23rd, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define NUM_LEDS 6
  4. #define DATA_PIN PB3
  5.  
  6. // Define the array of leds
  7. CRGB leds[NUM_LEDS];
  8.  
  9. void setup() {
  10.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  11.   randomSeed(analogRead(0) + analogRead(1) + analogRead(2) + analogRead(3) + analogRead(4) + analogRead(5));
  12. }
  13.  
  14. void random_pixel_color(int ledID) {
  15.   for (byte colorID = 0; colorID < 3; colorID++) {
  16.     leds[ledID][colorID] = random(0, 255);
  17.   }
  18.   FastLED.show();
  19. }
  20.  
  21. void turn_pixel_off(int ledID) {
  22.   leds[ledID] = CRGB::Black;
  23.   FastLED.show();
  24. }
  25.  
  26.  
  27. void loop() {
  28.   int randomLedID = random(0,NUM_LEDS);
  29.   byte on_or_off =  random(0,10);
  30.   if (on_or_off != 0) {
  31.     random_pixel_color(randomLedID);
  32.   } else {
  33.     turn_pixel_off(randomLedID);
  34.   }
  35.   delay(random(150,350));
  36. }
Advertisement
Add Comment
Please, Sign In to add comment