(NOTE: I'll be representing RGB values like this for this post: (RED, GREEN, BLUE), but in the code it's handled by three variables LED_RV, LED_GV, LED_BV)
Hello,
My name is Luis and I have been having a problem with my project, as you might have read in the title, I want to dim a LED using an IR remote, as in make it less bright, but when I try to do this by lowering it's RGB values, the colour just changes from white (255, 255, 255) to blue (254, 254, 254), which I was expecting would lower the LED's brightness.
(NOTE: The LED does turn off when the RGB Values are 0,0,0, but even at 1,1,1 the colour and brightness is the same as 254,254,254.).
Here's the section of my code that does that (Lower RGB Values):
(Library Used: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols )
#include <IRremote.h>
const int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
int LED_R = 3;
int LED_RValue = 255;
int LED_B = 5;
int LED_BValue = 255;
int LED_G = 6;
int LED_GValue = 255;
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
int Results = results.value;
if (Results == 4080) {
if (LED_RValue != 0) {
Serial.print("LED_RValue = ");
LED_RValue--;
Serial.println(LED_RValue);
}
if (LED_GValue != 0) {
Serial.print("LED_GValue = ");
LED_GValue--;
Serial.println(LED_GValue);
}
if (LED_BValue != 0) {
Serial.print("LED_BValue = ");
LED_BValue--;
Serial.println(LED_BValue);
}
analogWrite(LED_R, LED_RValue);
analogWrite(LED_G, LED_GValue);
analogWrite(LED_B, LED_BValue);
}
//irrecv.resume(); //De-comment if you want to lower the values on a press-by-press basis
}
}
And here's the complete version of the code if needed.
#include <IRremote.h>
const int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
int Remote_CmndinDec;
int Remote_LastCmndinDec;
int LED_R = 3;
int LED_RV = 255;
int LED_B = 5;
int LED_BV = 255;
int LED_G = 6;
int LED_GV = 255;
void setup() {
Serial.begin(9600);
pinMode(4, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
Remote_CmndinDec = results.value;
if (Remote_CmndinDec == -1) {
ActionEggxecute (Remote_LastCmndinDec);
Serial.print("Remote_LastCmndinDec = ");
Serial.println(Remote_LastCmndinDec);
} else {
Serial.print("Remote_CmndinDec = ");
Serial.println(Remote_CmndinDec);
ActionEggxecute (Remote_CmndinDec);
Remote_LastCmndinDec = Remote_CmndinDec;
digitalWrite(4, LOW);
}
irrecv.resume();
}
}
bool on;
void ActionEggxecute (int x) {
switch (x) {
case 4080:
analogWrite(LED_R, LED_RV);
analogWrite(LED_G, LED_GV);
analogWrite(LED_B, LED_BV);
on = true;
Serial.println("ON");
break;
case -28816:
analogWrite(LED_R, 0);
analogWrite(LED_G, 0);
analogWrite(LED_B, 0);
on = false;
Serial.println("OFF");
break;
case -12496:
break;
case -4336:
break;
case 20400:
if (LED_RV != 0) {
Serial.print("LED_RV = ");
LED_RV--;
Serial.println(LED_RV);
}
if (LED_GV != 0) {
Serial.print("LED_GV = ");
LED_GV--;
Serial.println(LED_GV);
}
if (LED_BV != 0) {
Serial.print("LED_BV = ");
LED_BV--;
Serial.println(LED_BV);
}
Serial.println(on);
if (on == true) {
analogWrite(LED_R, LED_RV);
analogWrite(LED_G, LED_GV);
analogWrite(LED_B, LED_BV);
}
break;
case 8160:
break;
case 32640:
break;
case -16576:
break;
case 16320:
break;
case -8416:
break;
case 24480:
break;
case -24736:
break;
case -1:
break;
default:
digitalWrite(4, HIGH);
break;
Serial.println (x);
}
}
Thanks in advance!
(Edit1: Solved by david_2018 (Thanks!))