Arduino RGB LED Strip Controller(renamed/updated)

So i have been searching the web non stop for a week to try and figure this out but i just cant seem to grasp the code for what i want.

Basic Abstract:

Arduino hooked up to LED strips with transistors on PWM pins. Also has ir reciever(i have that portion working) to recieve commands from my Harmony Remote.

What i need help with is this:

Having multiple scenes:

  1. Individual RGB control to set custom color using individual commands to increase or decrease each value.
  2. Full Brightness on all
  3. RGB gradual fade
  4. Audio sensitive light sequence.

I can get 2 and 3 no problem but my issue is with getting the code formatted to stop looping and increase the value for each led when i enter a command in the serial(in place of ir reciever cmands for ease of troubleshooting).

Is it possible to use switch case for this(currently cant get it to work)? Should i be using if else?

I am at home. I will post my code tomorrow for further guidance.

Thanks for your help.

desolation:
I will post my code tomorrow for further guidance.

There's not much point trying to answer your questions until you have done that.

So first off let me say, I know this isn’t right, I am in the process of learning the code and I would love for any input as to how I managed to eff this up.

So my main issue like I said before is that the program just loops continuously and there is no difference between the “r-minus” function and say if I had just set the pin to LOW.

Thanks again.

const int rpin = 3;
const int gpin = 5;
const int bpin = 6;


void setup() {
  // initialize serial communication:
  Serial.begin(9600); 
   // initialize the LED pins:
   pinMode(rpin, OUTPUT);
   pinMode(gpin, OUTPUT);
   pinMode(bpin, OUTPUT);


   
}
char inByte = Serial.read();


void loop() {
  // read the sensor:
if (Serial.available()) {
    inByte = Serial.read();}  
  
switch (inByte) {  
  
    case '1':
    Rplus();    
      Serial.println("R -");
      break;
      
    case '2':    
      digitalWrite(gpin, HIGH);
      Serial.println("G OFF");
      break;
      
    case '3':    
      digitalWrite(bpin, HIGH);
      Serial.println("B OFF");
      break;
      
    case '4':
    Rminus(); 
      Serial.println("R +");
      break;
      
    case '5':    
      digitalWrite(gpin, LOW);
      Serial.println("G ON");
      break;
      
    case '6':    
      digitalWrite(bpin, LOW);
      Serial.println("B ON");
      break;
      
    case '7':    
      Serial.println("RGB FADE");
      RGBFade();    
    break; 
    case '8':    
      Serial.println("Bight Light");
      digitalWrite(rpin, LOW);
      digitalWrite(gpin, LOW);
      digitalWrite(bpin, LOW);   
    break; 
    case '9':    
      Serial.println("Low Light");
      analogWrite(rpin, 128);
      analogWrite(gpin, 128);
      analogWrite(bpin, 128);   
    break;
    
    default:
      // turn all the LEDs off:
      for (int thisPin = 3; thisPin < 7; thisPin++) {
        digitalWrite(thisPin, HIGH);
      }
    }
 }
  
  
//Functions

//Red Increase Command
void Rplus () { 
int  rval;
int fade = -1;
rval == analogRead(rpin);
if(rval, -255>0);
{ analogWrite(rpin, rval + fade);
 
  }
}


//Red Decrease Command
void Rminus () { 
int  rval;
int fade = -1;
rval == analogRead(rpin);
if(rval, -255>0);
{ analogWrite(rpin, rval - fade);
  
  }
}


//RGB Fade Command
void RGBFade() {
 
  int redVal = 255;
  int blueVal = 0;
  int greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    greenVal += 1;
    redVal -= 1;
    analogWrite( gpin, 255 - greenVal );
    analogWrite( rpin, 255 - redVal );

    delay(10);
  }
 
  redVal = 0;
  blueVal = 0;
  greenVal = 255;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal += 1;
    greenVal -= 1;
    analogWrite( bpin, 255 - blueVal );
    analogWrite( gpin, 255 - greenVal );

    delay(10);
  }
 
  redVal = 0;
  blueVal = 255;
  greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    redVal += 1;
    blueVal -= 1;
    analogWrite( rpin, 255 - redVal );
    analogWrite( bpin, 255 - blueVal );

    delay(10);
  }
}

Maybe this question will make it more simple. How do i control an RGB led as if i were controlling volune. The up command and down command would individually control each leds brightness. Help please?

For those interested:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

  int wait = 10;
  int wait1 = 10;
  int redled = 9;    // assign LED to pin 9
  int grnled = 5;    // assign LED to pin 9
  int bluled = 6;    // assign LED to pin 9
  
  int command ;
  int fadered = -5;    // starting brightness values for each led
  int fadegrn = -5;    // starting brightness values for each led
  int fadeblu = -5;    // starting brightness values for each led
  
int redVal;
int blueVal;
int greenVal;
  
void setup () {
    Serial.begin(9600); 
      irrecv.enableIRIn(); // Start the receiver
      }

  void loop() {
    if( irrecv.decode(&results)) {
      
// increase red brightness
    command = (results.value);
    
    if(command == 16575 && fadered >= -250) {
      if(fadered == 255) {fadered = 0;} // if fade value is 255 (off) set it to 0
      // if button is pressed increase brightness by 5
      // as long as brightness isn't greater than -250
      fadered -=5;
      analogWrite(redled, fadered);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }
    
    
// decrease red brightness
       //check button state
    else if(command == 8415 && fadered <= -5) {
      // if button is pressed decrease brightness by 5
      // as long as brightness isn't less than -5
      fadered +=5;
      if(fadered == 0) {fadered = 255;}
      // when the fade value reaches 0, 255 is stored to the fade value to turn off the LED
      analogWrite(redled, fadered);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }
    
// increase green brightness
    //check button state
    else if(command == -24481 && fadegrn >= -250) {
      if(fadegrn == 255) {fadegrn = 0;} // if fade value is 255 (off) set it to 0
      // if button is pressed increase brightness by 5
      // as long as brightness isn't greater than -250
      fadegrn -=5;
      analogWrite(grnled, fadegrn);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }

// decrease green brightness

    else if(command == 24735 && fadegrn <= -5) {
      // if button is pressed decrease brightness by 5
      // as long as brightness isn't less than -5
      fadegrn +=5;
      if(fadegrn == 0) {fadegrn = 255;}
      // when the fade value reaches 0, 255 is stored to the fade value to turn off the LED
      analogWrite(grnled, fadegrn);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }
    
// increase blue brightness

    else if(command == 4335 && fadeblu >= -250) {
      if(fadeblu == 255) {fadeblu = 0;} // if fade value is 255 (off) set it to 0
      // if button is pressed increase brightness by 5
      // as long as brightness isn't greater than -250
      fadeblu -=5;
      analogWrite(bluled, fadeblu);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }

// decrease blue brightness
    else if(command == -8161 && fadeblu <= -5) {
      // if button is pressed decrease brightness by 5
      // as long as brightness isn't less than -5
      fadeblu +=5;
      if(fadeblu == 0) {fadeblu = 255;}
      // when the fade value reaches 0, 255 is stored to the fade value to turn off the LED
      analogWrite(bluled, fadeblu);  // lights LED at current brightness level
      delay(wait);  // allows time so button won't be detected multiple times
    }
    
//Low Light
    else if(command == 20655) {
      analogWrite(redled, 170);
      analogWrite(grnled, 170);
      analogWrite(bluled, 170);
      Serial.println("Low Light");
    }
    
//Bright Light    
    else if(command == 12495) {
      analogWrite(redled, 0);
      analogWrite(grnled, 0);
      analogWrite(bluled, 0);
      Serial.println("Bright Light");
    }
    
//RGB Fader   
    else if(command == 2295) {
  digitalWrite(redled, LOW);
  digitalWrite(grnled, LOW);
  digitalWrite(bluled, LOW);
      
  int redVal = 255;
  int blueVal = 0;
  int greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    greenVal += 1;
    redVal -= 1;
    analogWrite( grnled, 255 - greenVal );
    analogWrite( redled, 255 - redVal );

    delay( wait1 );
  }
 
  redVal = 0;
  blueVal = 0;
  greenVal = 255;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal += 1;
    greenVal -= 1;
    analogWrite( bluled, 255 - blueVal );
    analogWrite( grnled, 255 - greenVal );

    delay( wait1 );
  }
 
  redVal = 0;
  blueVal = 255;
  greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    redVal += 1;
    blueVal -= 1;
    analogWrite( redled, 255 - redVal );
    analogWrite( bluled, 255 - blueVal );

    delay( wait1 );
  }
      Serial.println("RGB Fade Sequence");}
    else{
      command = command;
    Serial.println(command);}
    irrecv.resume();
   }
  }

Everything is working pretty much perfectly, aside from the RGB Fade sequence.

Any ideas as to how to make it repeat indefinetely? At least until another keypress?