jedimasta

Photon WS2812b Palette

Oct 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. // This #include statement was automatically added by the Particle IDE.
  2. #include <FastLED.h>
  3.  
  4. FASTLED_USING_NAMESPACE;
  5.  
  6. #define LED_PIN     4
  7. #define COLOR_ORDER GRB
  8. #define CHIPSET     WS2811
  9. #define NUM_LEDS    300 //88 for testing, 300 for prodction
  10. #define BRIGHTNESS  150
  11. #define FRAMES_PER_SECOND 30
  12.  
  13. bool gReverseDirection = false;
  14. unsigned long previousMillis = 0;
  15. unsigned long currentMillis;
  16. unsigned long twinkleMillis = 0;
  17. int mode;
  18. long totalModes = 3;
  19.  
  20. CRGB leds[NUM_LEDS];
  21.  
  22. // Forward declarations of an array of cpt-city gradient palettes, and
  23. // a count of how many there are.  The actual color palette definitions
  24. // are at the bottom of this file.
  25. extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
  26. extern const uint8_t gGradientPaletteCount;
  27.  
  28. // Current palette number from the 'playlist' of color palettes
  29. uint8_t gCurrentPaletteNumber = 0;
  30.  
  31. CRGBPalette16 gCurrentPalette( CRGB::Black);
  32. CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
  33.  
  34. void setup() {
  35.   delay(3000); // sanity delay
  36.   FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  37.   FastLED.setBrightness( BRIGHTNESS );
  38.   //FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
  39.   randomSeed(analogRead(0));
  40.   //Serial.begin(9600);
  41.   mode = random(totalModes);
  42. }
  43.  
  44.  
  45. extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
  46.  
  47. void loop()
  48. {
  49.  
  50.  
  51. }
  52.  
  53.  
  54. void runRainbow() {
  55.   if (currentMillis - previousMillis >= 30) {
  56.     previousMillis = currentMillis;
  57.     static uint8_t hue = 0;
  58.     fill_rainbow(leds, NUM_LEDS, hue++);
  59.     FastLED.show();
  60.   }
  61. }
  62.  
  63. void twinkle() {
  64.   //create random twinkle
  65.   int rp = random(500,2000);
  66.   if (currentMillis - twinkleMillis >= rp) {
  67.     twinkleMillis = currentMillis;
  68.     int pixel = random(NUM_LEDS);
  69.     leds[random(NUM_LEDS)] = CRGB::White;
  70.     FastLED.show();
  71.   }
  72. }
  73.  
  74. void palettetest( const CRGBPalette16& gCurrentPalette)
  75. {
  76.   if (currentMillis - previousMillis >= 30) {
  77.     previousMillis = currentMillis;
  78.     static uint8_t startindex = 0;
  79.     startindex--;
  80.     fill_palette( leds, NUM_LEDS, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
  81.     FastLED.show();
  82.   }
  83. }
  84.  
  85. DEFINE_GRADIENT_PALETTE( holly_gp) {
  86.   0,    0,  255,  0,  //green
  87.   48,   0,  255,  0,  //green
  88.   49,   255,  0,  0,  //red
  89.   64,   255,  0,  0,  //red
  90.   65,   0,  255,  0,  //green
  91.   114,   0,  255,  0,  //green
  92.   115,   255,  0,  0,  //red
  93.   118,   255,  0,  0,  //red
  94.   119,   0,  255,  0,  //green
  95.   168,  0,  255,  0,  //green
  96.   169,  255,  0,  0,  //red
  97.   184,  255,  0,  0,  //red
  98.   185,  0,  255,  0,  //green
  99.   234,  0,  255,  0,  //green
  100.   235,  255,  0,  0,  //red
  101.   255,  255,  0,  0   //red
  102. };
  103.  
  104. DEFINE_GRADIENT_PALETTE( candycane_gp) {
  105.   0 , 128, 128, 128,  //white
  106.   32 , 128, 128, 128,  //white
  107.   33 , 255, 0, 0,  //red
  108.   66 , 255, 0, 0,  //red
  109.   67 , 128, 128, 128,  //white
  110.   100 , 128, 128, 128,  //white
  111.   101 , 255, 0, 0,  //red
  112.   134 , 255, 0, 0,  //red
  113.   135 , 128, 128, 128,  //white
  114.   168 , 128, 128, 128,  //white
  115.   169 , 255, 0, 0,  //red
  116.   202 , 255, 0, 0,  //red
  117.   203 , 128, 128, 128,  //white
  118.   236 , 128, 128, 128,  //white
  119.   237 , 255, 0, 0,  //red
  120.   255 , 255, 0, 0  //red
  121. };
  122.  
  123. DEFINE_GRADIENT_PALETTE( snowynight_gp) {
  124.   0, 163, 182, 199,
  125.   41,  188, 192, 200,
  126.   117,  117, 157, 240,
  127.   204,  117, 224, 240,
  128.   255,  163, 182, 199
  129. };
  130.  
  131. DEFINE_GRADIENT_PALETTE( silvergold_gp) {
  132.   46, 191, 201, 224,
  133.   127, 255, 236, 133,
  134.   204, 191, 201, 224
  135. };
  136.  
  137. const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
  138.   holly_gp,
  139.   candycane_gp,
  140.   snowynight_gp,
  141.   silvergold_gp
  142. };
Advertisement
Add Comment
Please, Sign In to add comment