The white and blue blinking happens because the IR library uses a hardware timer that conflicts with analogWrite() on certain pins. Check that your LED/motor pins do not use the same timer as the IR receiver. Moving the LED to a different pin or avoiding analogWrite() on those pins should fix it.
@roelofw coukd you make a wokwi with the original code, and lock it (or stop playing with it) so it doesn't change under our feet?
I went "back in" to run this to ground and found the project basically gone.
But… the last thing I did was terribly alarming and suggests entirely new experiments, as well as invalidating many of the preliminary conclusions I had on the table.
I use different browsers on my machine, and also use several machines with different browsers.
I had very simple code mjsbehaving nicely (!) and for no particular reason moved it to another browser and… the LED which was a pulsating mess became solid bright white.
I'll do it again carefully and may contribute to the issue on github. I fear, however, that if someone can say it is broken in such-and-such a way on Browser X version Y, it will just be true, not turn into an action item for wokwi - faithful replication of the appearance of LEDs is tricky in simulation, for reasons; it's just a fact of life, a known feature.
I try to remember to tell ppl not to make too much of how LEDs look and work in the sim… real life may be different and any serious project where care about exactly what things look like must include real life tests with the actual LEDs and the current you plan on using deployed in the same mechanical circumstances.
I rewrote the code with wokwi and the IR library and relevant pins.
Running this in Safari on a Mac, the colors seems largely OK - no blinking or whatever.
click to see the code
#include <IRremote.hpp>
const byte irReceivePin = 2;
const byte rPin = 9;
const byte gPin = 6;
const byte bPin = 5;
byte r, g, b;
void handleCommand() {
if (IrReceiver.decode()) {
switch (IrReceiver.decodedIRData.command) {
case 162: r = 255; g = 105; b = 180; Serial.println("HOT PINK"); break; // POWER
case 226: r = 0; g = 128; b = 128; Serial.println("TEAL"); break; // MENU
case 34: r = 210; g = 105; b = 30; Serial.println("CHOCOLATE"); break; // TEST
case 2: r = 255; g = 192; b = 203; Serial.println("PINK"); break; // PLUS
case 194: r = 128; g = 0; b = 128; Serial.println("PURPLE"); break; // BACK
case 224: r = 255; g = 140; b = 0; Serial.println("DARK ORANGE"); break; // PREV.
case 168: r = 64; g = 224; b = 208; Serial.println("TURQUOISE"); break; // PLAY
case 144: r = 0; g = 255; b = 127; Serial.println("SPRING GREEN"); break; // NEXT
case 152: r = 255; g = 215; b = 0; Serial.println("GOLD"); break; // MINUS
case 176: r = 128; g = 128; b = 0; Serial.println("OLIVE"); break; // key: C
case 104: r = 0; g = 0; b = 0; Serial.println("BLACK"); break; // 0
case 48: r = 255; g = 0; b = 0; Serial.println("RED"); break; // 1
case 24: r = 255; g = 127; b = 0; Serial.println("ORANGE"); break; // 2
case 122: r = 255; g = 255; b = 0; Serial.println("YELLOW"); break; // 3
case 16: r = 0; g = 255; b = 0; Serial.println("GREEN"); break; // 4
case 56: r = 0; g = 255; b = 255; Serial.println("CYAN"); break; // 5
case 90: r = 0; g = 0; b = 255; Serial.println("BLUE"); break; // 6
case 66: r = 75; g = 0; b = 130; Serial.println("INDIGO"); break; // 7
case 74: r = 148; g = 0; b = 211; Serial.println("VIOLET"); break; // 8
case 82: r = 255; g = 255; b = 255; Serial.println("WHITE"); break; // 9
default: break;
}
analogWrite(rPin, r);
analogWrite(gPin, g);
analogWrite(bPin, b);
IrReceiver.resume();
}
}
void setup() {
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
Serial.begin(115200);
IrReceiver.begin(irReceivePin);
Serial.println(F("Ready"));
}
void loop() {
handleCommand();
}
I can't try it in Safari because I can't move up to a later operating system to get a version that can run wokwi because I have so much software that would break if I did. Use a modern MacOS.
But I totally believe you. THX for going to the trouble. I think it is safe to assume the OP's code would not have the issue.