Description
Hi, maybe there is a bug in the pwm function of analogWrite with the latest changes. I have testet 2.4.2 and latest git. If you try to set 3 pwm channels at once like in the function below to set the rgb color of a LED Stripe, you wont get every color updated correctly.
void setColorToOutput(uint8_t r, uint8_t g, uint8_t b) {
analogWrite(14, r);
analogWrite(12, g);
analogWrite(13, b);
}
The configuration of the pwm is as follows for both functions:
analogWriteFreq(1000);
analogWriteRange(255);
There was a very strange behaviour: F.E. if i got to the color yellow direktly (r=255, g=150, b=0) there was only red LEDs on but when i switched from green (r=0, g=255,b=0) to yellow it seems to work but with (g=255). From my research of this behavior i think there is a problem with updating the values, when they are not min or max. If you update to min or max it works but if you update within the range of the pwm, so if the old value is not 0 or 255, in my case , it will not update the output.
While testing and trying to fix that i found the following solution by changing my function a littlebit:
static uint8_t rOld = 0;
static uint8_t gOld = 0;
static uint8_t bOld = 0;
void setColorToOutput(uint8_t r, uint8_t g, uint8_t b) {
if (r != rOld) {
analogWrite(14, 0);
analogWrite(14, r);
rOld = r;
}
if (g != gOld) {
analogWrite(12, 0);
analogWrite(12, g);
gOld = g;
}
if (b != bOld) {
analogWrite(13, 0);
analogWrite(13, b);
bOld = b;
}
}
These changes are a very quick and dirty patch and now it works like a charm. So I assume there is somewhere a bug in updating the pwm values for an existing waveform object.