So I made a this in TinkerCAD:
The code inside the Adruino Uno:
#include <IRremote.h>
#include <LiquidCrystal.h>
//----Variables-----\\
const int RedPin = 11;
const int GreenPin = 9;
const int BluePin = 10;
const int IRrecvPin = 12;
int ColourRed = 255;
int ColourGreen = 255;
int ColourBlue = 255;
int WhichMode = 0;
boolean LCDPressOn = false;
boolean LEDOn = false;
String CurrentColour[8] = {"w", "r", "g", "b", "o", "y", "a", "p"};
int ColourTracker = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // Initialize the LCD Pins
IRrecv irrecv(IRrecvPin); //Start the IR
decode_results results; //Start the IR
unsigned long key_value = 0;
//---Custom-Characters---\\
byte PowerButton[8] = {
B00000,
B00100,
B01110,
B10101,
B10001,
B10001,
B01110,
B00000
};
//-----Start-Once-----\\
void setup(){
Serial.begin(9600);
pinMode(BluePin, OUTPUT);
pinMode(RedPin, OUTPUT);
pinMode(GreenPin, OUTPUT);
lcd.begin(16, 2);
lcd.createChar(2, PowerButton);
irrecv.enableIRIn();
irrecv.blink13(true);
}
//-------Repeat-------\\
void loop(){
TranslateIR();
LCD();
}
//---LCD---\\
void LCD() {
if (LEDOn && LCDPressOn == false && WhichMode == 0){
lcd.setCursor(0, 0);
lcd.print(" LED On ");
lcd.setCursor(0, 1);
lcd.print(" ");
delay(1000);
LCDPressOn = true;
} else if (LEDOn && LCDPressOn && WhichMode == 0) {
lcd.setCursor(0, 0);
lcd.print(" Current Values ");
lcd.setCursor(0, 1);
lcd.print("RGB= ");
lcd.print(ColourRed);
lcd.print(",");
lcd.print(ColourGreen);
lcd.print(",");
lcd.print(ColourBlue);
delay(1000);
} else if (LEDOn == false && WhichMode == 0) {
lcd.setCursor(0, 0);
lcd.print(" LED Off ");
lcd.setCursor(0, 1);
lcd.print(" Press ");
lcd.setCursor(10, 1);
lcd.write(2);
lcd.setCursor(11, 1);
lcd.print(" ");
delay(1000);
} else if (LEDOn && WhichMode == 1) { // Red
lcd.setCursor(0, 0);
lcd.print("(-/+) Red");
lcd.setCursor(0, 1);
lcd.print("Value = ");
lcd.print(ColourRed);
delay(1000);
} else if (LEDOn && WhichMode == 2) { // Green
lcd.setCursor(0, 0);
lcd.print("(-/+) Green");
lcd.setCursor(0, 1);
lcd.print("Value = ");
lcd.print(ColourGreen);
delay(1000);
} else if (LEDOn && WhichMode == 3) { // Blue
lcd.setCursor(0, 0);
lcd.print("(-/+) Blue");
lcd.setCursor(0, 1);
lcd.print("Value = ");
lcd.print(ColourBlue);
delay(1000);
} else if (LEDOn && WhichMode == 4) { // Default
WhichMode = 0;
LCDPressOn = true;
}
}
//---Change-Values-RGB---\\
void ChangeValueN() {
if (LEDOn) {
if (WhichMode == 1) {
ColourRed = ColourRed - 10;
if (ColourRed < 0) ColourRed = 0;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
} else if (WhichMode == 2) {
ColourGreen = ColourGreen - 10;
if (ColourGreen < 0) ColourGreen = 0;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
} else if (WhichMode == 3) {
ColourBlue = ColourBlue - 10;
if (ColourBlue < 0) ColourBlue = 0;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
}
}
void ChangeValueP() {
if (LEDOn) {
if (WhichMode == 1) {
ColourRed = ColourRed + 10;
if (ColourRed > 255) ColourRed = 255;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
} else if (WhichMode == 2) {
ColourGreen = ColourGreen + 10;
if (ColourGreen > 255) ColourGreen = 255;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
} else if (WhichMode == 3) {
ColourBlue = ColourBlue + 10;
if (ColourBlue > 255) ColourBlue = 255;
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
}
}
//-----Set-LED-----\\
void SetLED() {
if (CurrentColour[ColourTracker].equals("w")) {
ColourRed = 255;
ColourGreen = 255;
ColourBlue = 255;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("r")) {
ColourRed = 255;
ColourGreen = 0;
ColourBlue = 0;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("g")) {
ColourRed = 0;
ColourGreen = 255;
ColourBlue = 0;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("b")) {
ColourRed = 0;
ColourGreen = 0;
ColourBlue = 255;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("o")) {
ColourRed = 255;
ColourGreen = 69;
ColourBlue = 0;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("y")) {
ColourRed = 255;
ColourGreen = 255;
ColourBlue = 0;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("a")) {
ColourRed = 0;
ColourGreen = 255;
ColourBlue = 255;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
} else if (CurrentColour[ColourTracker].equals("p")) {
ColourRed = 255;
ColourGreen = 0;
ColourBlue = 255;
if (LEDOn) {
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
}
}
}
//-----Toggle-LED-----\\
void ToggleLED() {
if (LEDOn) {
Serial.println("LED turned off");
analogWrite(RedPin, 0);
analogWrite(GreenPin, 0);
analogWrite(BluePin, 0);
LEDOn = false;
delay(200);
} else {
Serial.println("LED turned on");
analogWrite(RedPin, ColourRed);
analogWrite(GreenPin, ColourGreen);
analogWrite(BluePin, ColourBlue);
LEDOn = true;
delay(200);
}
}
//----Cycle----\\
void Cycle() {
if (LEDOn) {
ColourTracker++;
if (ColourTracker > 7 || ColourTracker < 0) {
ColourTracker = 0;
}
}
}
//---Cycle-Modes---\\
void CycleMode() {
if (LEDOn){
WhichMode++;
if (WhichMode > 4 || WhichMode < 0) {
WhichMode = 0;
}
}
}
//-----Translate-IR----\\
void TranslateIR() {
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF) results.value = key_value;
switch(results.value) {
case 0xFD00FF:
Serial.println("POWER");
lcd.clear();
ToggleLED();
delay(500);
break;
case 0xFD40BF:
Serial.println("FUNC/STOP");
lcd.clear();
Cycle();
SetLED();
delay(500);
break;
case 0xFDA05F:
Serial.println(">||");
lcd.clear();
CycleMode();
delay(500);
break;
case 0xFD20DF:
Serial.println("|<<");
lcd.clear();
ChangeValueN();
delay(100);
break;
case 0xFD609F:
Serial.println(">>|");
lcd.clear();
ChangeValueP();
delay(100);
break;
}
Serial.println(results.value);
key_value = results.value;
irrecv.resume();
}
}
So my problem is that when I cycle through the modes (by pressing pause button) and decrease or increase the values of the colours (by pressing |<< or >>| buttons), only the blue and green work, but the red doesn't and I can't figure the problem out.
Edit: When I press |<< then the code for all buttons change randomly. But only when the mode is on the red and then I press |<<.