Hello there,
Since I am a rookie in arduino I look for help. I want to control a RGB LED with a remote control. Now I've come to the point where I want to set the brightness of each color individually. Like having color "red" selected and now changing the brightness of "red" with 2 Button on my remote Control (for + and -).
When I want to change the color the brightness should be on the same level as before. For Example for red I want a brightness of 200 the next color should also have a brightness of 200.
I've searched through the internet without finding a solution.
This is how far I came:
#include <IRremote.h>
const int recvPin = 5; //IR Input
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
//Initializing the Receiver Pin
IRrecv irrecv(recvPin);
decode_results results; //decoding Decode-Results in variable "results"
unsigned long key_val = 0; //storing code when same button is pressed again
void setup() {
irrecv.enableIRIn(); //Starting Receiver
irrecv.blink13(true); //Arduino led blinking when receiving an incoming button-code
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
if(irrecv.decode(&results)){
if(results.value == 0xFFFFFFFF){
results.value = key_val; //Storing button hex-code if same button is pressed again
}
if(results.value == 0xFFA25D){ //If Remote Control pressed button "1"
setColor(255, 0, 0); //color red
}else
if(results.value == 0xFF629D){ //If Remote Control pressed button "2"
setColor(0, 255, 0); //color green
}else
if(results.value == 0xFFE21D){ //If Remote Control pressed button "3"
setColor(0, 0, 255); //Color blue
}
else { //If any other button is pressed
setColor(0, 0, 0); //RGB LED Off
}
key_val = results.value;
irrecv.resume(); //Clearing button for next incoming button
}
}
void setColor(int red, int green, int blue){ //Setting the rgb LED to RGB
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
I addressed 3 Buttons with red, green and blue. Now I want to change with 2 Buttons the brightness. Is there a way you could help me?
Thank you in advance.