Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2022
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // the whole strip
  4. #define NUM_LEDS 9
  5.  
  6. #define LED_PIN 6
  7.  
  8. CRGB leds[NUM_LEDS];
  9.  
  10. // Define the indexes of the first and last 3 indexes of a 9 pixel strip
  11. bool customLeds[9] = {1, 1, 1, 0, 0, 0, 1, 1, 1};
  12.  
  13. // Number of Leds that need addressing in the above array
  14. int customLeds_num = 6;
  15.  
  16. // My Palette
  17. DEFINE_GRADIENT_PALETTE (heatmap) {
  18.   0, 255, 0, 0,      // Red
  19.   128, 0, 255, 0,    // Green
  20.   255, 0, 0, 255     // Blue
  21. };
  22.  
  23. DEFINE_GRADIENT_PALETTE (heatmap2) {
  24.   0, 0, 255, 255,      // Cyan
  25.   128, 255, 0, 255,    // Magenta
  26.   255, 255, 255, 0     // Yellow
  27. };
  28.  
  29. CRGBPalette16 myPalette1 = heatmap;
  30. CRGBPalette16 myPalette2 = heatmap2;
  31.  
  32. void setup() {
  33.   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  34.   FastLED.setBrightness(20);
  35.   Serial.begin(9600);
  36. }
  37.  
  38. void loop() {
  39.  
  40.   uint8_t hue = 0;
  41.   FastLED.clear();
  42.  
  43.   //  Keep track of how many Leds have been lit
  44.   int customLedIndex1 = 0;
  45.   int customLedIndex2 = 0;
  46.  
  47.   for (int i = 0; i < NUM_LEDS; i++) {
  48.     // Each i led get the correct color given their place in the array  - 0, 51, 102, 153, 204, 255
  49.  
  50.     //lights a speficic pixel only if it's in the customLeds truth table
  51.     if (customLeds[i]) {
  52.       // works out where on the gradient a specific pixel is
  53.       hue = (customLedIndex1 * (255 / (customLeds_num - 1)));
  54.  
  55.       //I'm sure the trouble lies in this bit of code
  56.       leds[i] = ColorFromPalette(myPalette1, hue , 255, LINEARBLEND);
  57.  
  58.       // Output to check the value...which seem to check out
  59.       Serial.print(customLedIndex1);
  60.       Serial.println(hue);
  61.      
  62.       //increments the index for the next pixels value on the gradient
  63.       customLedIndex1++;
  64.  
  65.     }
  66.   }
  67.   FastLED.show();
  68.   customLedIndex1 = 0;
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement