Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define FASTLED_ALLOW_INTERRUPTS 0
  2. #include <FastLED.h>
  3.  
  4.  
  5. #define LED_PIN     3
  6. #define NUM_LEDS    60
  7. #define BRIGHTNESS  128
  8. #define LED_TYPE    WS2812B
  9. #define COLOR_ORDER GRB
  10.  
  11. CRGB leds[NUM_LEDS];
  12. int value;
  13. int led;
  14.  
  15.  
  16. void setup() {
  17.   delay(1000);
  18.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  19.   FastLED.setBrightness(BRIGHTNESS);
  20.  
  21.   for (int p = 0; p <= 13; p++) {
  22.     pinMode(p, OUTPUT);
  23.     digitalWrite(p, 0);
  24.   }
  25.  
  26.   Serial.begin(57600);
  27. }
  28.  
  29. void loop() {
  30.   while (Serial.available() >= 3 && Serial.read() == 0xff) {
  31.     value = Serial.read();
  32.    
  33.     if(value == 36) {
  34.       for(int l = 0; l < NUM_LEDS; l++) {
  35.         if(l % 2 == 0) {
  36.           leds[l] = CRGB::Yellow;
  37.         } else {
  38.           leds[l]=  CRGB::Red;
  39.         }
  40.       }
  41.     } else {
  42.       leds[random(0, NUM_LEDS-1)] = CHSV(map(value, 0, 127, 0, 255), 230, 230);
  43.     }
  44.   }
  45.  
  46.   if (millis() % 5 == 0)
  47.     for (int i = 0; i < NUM_LEDS; i++)
  48.       leds[i].fadeToBlackBy(64);
  49.  
  50.   FastLED.show();  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement