Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- // the whole strip
- #define NUM_LEDS 9
- #define LED_PIN 6
- CRGB leds[NUM_LEDS];
- // Define the indexes of the first and last 3 indexes of a 9 pixel strip
- bool customLeds[9] = {1, 1, 1, 0, 0, 0, 1, 1, 1};
- // Number of Leds that need addressing in the above array
- int customLeds_num = 6;
- // My Palette
- DEFINE_GRADIENT_PALETTE (heatmap) {
- 0, 255, 0, 0, // Red
- 128, 0, 255, 0, // Green
- 255, 0, 0, 255 // Blue
- };
- DEFINE_GRADIENT_PALETTE (heatmap2) {
- 0, 0, 255, 255, // Cyan
- 128, 255, 0, 255, // Magenta
- 255, 255, 255, 0 // Yellow
- };
- CRGBPalette16 myPalette1 = heatmap;
- CRGBPalette16 myPalette2 = heatmap2;
- void setup() {
- FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
- FastLED.setBrightness(20);
- Serial.begin(9600);
- }
- void loop() {
- uint8_t hue = 0;
- FastLED.clear();
- // Keep track of how many Leds have been lit
- int customLedIndex1 = 0;
- int customLedIndex2 = 0;
- for (int i = 0; i < NUM_LEDS; i++) {
- // Each i led get the correct color given their place in the array - 0, 51, 102, 153, 204, 255
- //lights a speficic pixel only if it's in the customLeds truth table
- if (customLeds[i]) {
- // works out where on the gradient a specific pixel is
- hue = (customLedIndex1 * (255 / (customLeds_num - 1)));
- //I'm sure the trouble lies in this bit of code
- leds[i] = ColorFromPalette(myPalette1, hue , 255, LINEARBLEND);
- // Output to check the value...which seem to check out
- Serial.print(customLedIndex1);
- Serial.println(hue);
- //increments the index for the next pixels value on the gradient
- customLedIndex1++;
- }
- }
- FastLED.show();
- customLedIndex1 = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement