SHARE
TWEET

Untitled

a guest Apr 3rd, 2019 225 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2. #define LED_PIN     3                //CONFIGURE LED STRIP HERE
  3. #define NUM_LEDS    30
  4. #define BRIGHTNESS  255
  5. #define LED_TYPE    WS2812B
  6. #define COLOR_ORDER GRB
  7. CRGB leds[NUM_LEDS];
  8. #define UPDATES_PER_SECOND 100
  9.  
  10. //Previous value of RGB
  11. int redPrevious, greenPrevious, bluePrevious = 0;
  12.  
  13. //Current value of RGB
  14. float redCurrent, greenCurrent, blueCurrent = 0;
  15.  
  16. //Target value of RGB
  17. int redTarget, greenTarget, blueTarget = 0;
  18.  
  19. int fade_delay = 10;
  20. int steps = 100;
  21.  
  22. void setup() {
  23.   Serial.begin(9600);
  24.   delay( 3000 ); // power-up safety delay
  25.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  26.  
  27. }
  28. void loop() {
  29.  
  30.   FadeToColour(66, 101, 244);
  31.   FadeToColour(143, 65, 244);
  32.   FadeToColour(66, 101, 244);
  33. }
  34.  
  35. void FadeToColour(int r, int g, int b) {
  36.   redPrevious = redCurrent;
  37.   greenPrevious = greenCurrent;
  38.   bluePrevious = blueCurrent;
  39.  
  40.   redTarget = r;
  41.   greenTarget = g;
  42.   blueTarget = b;
  43.  
  44.   float redDelta = redTarget - redPrevious;
  45.   redDelta = redDelta / steps;
  46.  
  47.   float greenDelta = greenTarget - greenPrevious;
  48.   greenDelta = greenDelta / steps;
  49.  
  50.   float blueDelta = blueTarget - bluePrevious;
  51.   blueDelta = blueDelta / steps;
  52.  
  53.   for (int j = 1; j < steps; j++) {
  54.     redCurrent = redPrevious + (redDelta * j);
  55.     greenCurrent = greenPrevious + (greenDelta * j);
  56.     blueCurrent = bluePrevious + (blueDelta * j);
  57.     setColour(redCurrent, greenCurrent, blueCurrent, 6);
  58.     delay(fade_delay);  //Delay between steps
  59.   }
  60.   delay(1000); //Wait at peak colour before continuing
  61. }
  62.  
  63. void setColour(int r, int g, int b, int lednum) {
  64.   Serial.println(r);
  65.   leds[6] = CRGB(r, g, b);
  66.   FastLED.show();
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top