I have a strange behavior with my code. I use FastLed to blink a ledstrip.
I have a function in a Ledstrip.cpp file :
void LedStrip::setPixel(uint32_t num, int color)
{
Serial.println(num);
leds[num].b=(color & 0xFF); // Take just the lowest 8 bits.
leds[num].g=((color >> 8)& 0xFF); // Shift the integer right 8 bits.
leds[num].r=((color >> 16)& 0xFF); // Shift the integer right 8 bits.
}
Serial.println(num);
leds[num].b=(color & 0xFF); // Take just the lowest 8 bits.
leds[num].g=((color >> 8)& 0xFF); // Shift the integer right 8 bits.
leds[num].r=((color >> 16)& 0xFF); // Shift the integer right 8 bits.
}
Despite what the comment says, you are shifting a 16-bit int right by 16 bits. All of the data will shift off the end, leaving nothing for Red. If the high bit of Green is a 1 you might end up with 255 (sign extension), otherwise 0.
Yes the comment are bad :), but the code works for the colors (I can use red, green and blue without problems). The only problem is the value of num, if I print it before with Serial.println and I call ...setPixel(0,...) The first led illuminates, If I remove the println, The led ~120 illuminates. It's like a problem of cast without the Serial.println
kakou:
Yes the comment are bad :), but the code works for the colors (I can use red, green and blue without problems).
In that case you have a problem not only with this part of the program, but also the part that uses leds[] to actually output to the LEDs. Because, reply #4 is correct, that code can not possibly work.
Try adding a FastLED.setDither( 0 ); to your void LedStrip::begin(void) and see if there is any behaviour change.
Otherwise, can you slim your ArduinoStripController.ino down to the minimum required to reproduce the problem and post it. Please also accurately describe what happens in the slimmed down version.