Advertisement
atuline

Some fading, but not a good example of it.

Apr 13th, 2019
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. // Not a good example.
  2.  
  3. #include "FastLED.h"
  4. #define NUM_LEDS 40
  5. CRGB leds[NUM_LEDS];
  6. #define PIN 12
  7.  
  8.  
  9. void setup()
  10. {
  11.   LEDS.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  12.   FastLED.setBrightness(64);
  13. }
  14.  
  15. void loop() {
  16.  
  17.   FadeInOut(0xF8, 0xF8, 0xFF);
  18.  
  19.   FastLED.show();
  20. }
  21.  
  22.  
  23. void FadeInOut(byte red, byte green, byte blue){
  24.  
  25.   float r, g, b;
  26.      
  27.   for(int k = 0; k < 256; k++) {
  28.     r = (k/256.0)*red;
  29.     g = (k/256.0)*green;
  30.     b = (k/256.0)*blue;
  31.     setAll(r,g,b);
  32.     FastLED.delay(10);
  33.   }
  34.      
  35.   for(int k = 255; k > 0; k--) {
  36.     r = (k/256.0)*red;
  37.     g = (k/256.0)*green;
  38.     b = (k/256.0)*blue;
  39.     setAll(r,g,b);
  40.     FastLED.delay(10);
  41.   }
  42. }
  43.  
  44. void setAll(byte red, byte green, byte blue) {
  45.   for(int i = 0; i < NUM_LEDS; i++ ) {
  46.     leds[i].r = red;
  47.     leds[i].g = green;
  48.     leds[i].b = blue;
  49.   }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement