#include <IRremote.hpp>
const int RX_PIN = 2;
const int RED_PIN = 10;
const int GRN_PIN = 9;
const int BLU_PIN = 6;
/*
const byte KEY_CODES[] = {
see https://docs.wokwi.com/parts/wokwi-ir-remote
162, 226, 34, 2, 194,
224, 168, 144, 152, 176,
104, 48, 24, 122, 16,
56, 90, 66, 74, 82
};
*/
bool isAllOn = false;
bool isRedOn = false;
bool isGrnOn = false;
bool isBluOn = false;
int lightVal = 250;
void lightLeds(int command) {
Serial.println(command); // for test
switch (command) {
case 162: // power
isAllOn = !isAllOn;
break;
case 48: // 1
isRedOn = !isRedOn;
break;
case 24: // 2
isGrnOn = !isGrnOn;
break;
case 122: // 3
isBluOn = !isBluOn;
break;
case 2: // +
lightVal += 50;
if (lightVal >= 250) lightVal = 250;
break;
case 152: // -
lightVal -= 50;
if (lightVal <= 0) lightVal = 0;
break;
default:
break;
}
if (isRedOn && isAllOn) {
analogWrite(RED_PIN, lightVal);
} else {
analogWrite(RED_PIN, 0);
}
if (isGrnOn && isAllOn) {
analogWrite(GRN_PIN, lightVal);
} else {
analogWrite(GRN_PIN, 0);
}
if (isBluOn && isAllOn) {
analogWrite(BLU_PIN, lightVal);
} else {
analogWrite(BLU_PIN, 0);
}
}
void setup() {
Serial.begin(115200);
IrReceiver.begin(RX_PIN, ENABLE_LED_FEEDBACK);
pinMode(RED_PIN, OUTPUT);
pinMode(GRN_PIN, OUTPUT);
pinMode(BLU_PIN, OUTPUT);
}
void loop() {
if (IrReceiver.decode()) { // received IR
int command = IrReceiver.decodedIRData.command;
lightLeds(command);
IrReceiver.resume(); // prepare for the next IR
}
}
Power is all on / off
+ / - adjust brightness
1, 2, 3 is R, G, B