Hi! really appreciate your time trying to help me out. I have adjusted my code to use an array and can clearly see it was the better option. However, I still cannot seem to be able to dim the light. I'll post my code below.
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int redPin = 11;
const int greenPin = 10;
const int bluePin = 6;
static int rgbValues[] = {255, 255, 255};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (irrecv.decode(&results)){
switch(results.value){
case 0xFF30CF: //Keypad button 1
rgbValues[0] = 255;
rgbValues[1] = 0;
rgbValues[2] = 0;
break;
case 0xFF18E7: //Keypad button 2
rgbValues[0] = 0;
rgbValues[1] = 255;
rgbValues[2] = 0;
break;
case 0xFF7A85: //Keypad button 3
rgbValues[0] = 0;
rgbValues[1] = 0;
rgbValues[2] = 255;
break;
case 0xFF6897: //Keypad button 0
rgbValues[0] = 0;
rgbValues[1] = 0;
rgbValues[2] = 0;
break;
case 0xFF10EF: //Keypad button 4
rgbValues[0] = 255;
rgbValues[1] = 255;
rgbValues[2] = 255;
break;
case 0xFF02FD: //Keypad button play/pause
Serial.print("Red value is "); Serial.println(rgbValues[0]);
Serial.print("Green value is "); Serial.println(rgbValues[1]);
Serial.print("Blue value is "); Serial.println(rgbValues[2]);
break;
case 0xFFE01F: //Keypad button down
if(rgbValues[0] >= 10){
rgbValues[0] = rgbValues[0] - 10;
}
else{
rgbValues[0] = rgbValues[0] * 1;
}
if(rgbValues[1] >= 10){
rgbValues[1] = rgbValues[1] - 10;
}
else{
rgbValues[1] = rgbValues[1] * 1;
}
if(rgbValues[2] >= 10){
rgbValues[2] = rgbValues[2] - 10;
}
else{
rgbValues[2] = rgbValues[2] * 1;
}
Serial.print("Red value is "); Serial.println(rgbValues[0]);
Serial.print("Green value is "); Serial.println(rgbValues[1]);
Serial.print("Blue value is "); Serial.println(rgbValues[2]);
break;
}
RGB_colour(rgbValues[0], rgbValues[1], rgbValues[2]);
irrecv.resume();
}
}
void RGB_colour(int redValue, int greenValue, int blueValue){
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
I can confirm that when I switch through the different colours and print the values on screen they do change to the specified value. I can flick between them as much as I want. When i press 0 to change the RGB values to 0,0,0 and try to dim then the values stay at 0 as I wanted and I can flick back to another colour.
However, when I try to dim with a value above 10 then the specified amount is taken off the RGB value, it is printed to the screen but the actual RGB light does not change colour and I cannot change the colour back after pressing the dim button. I have to reset the board to be able to flip between the colours again.
Thanks again if anyone is able to help me out.