Go Down

Topic: Selecting output to multiple pins (Read 533 times) previous topic - next topic

jerandavies

i got my arduino today to control three different sets of rgb led strips so cathodes in total. my question is i want to display all three strips different colours, ie when one is red one is blue and one is green which can be done by putting the wires in wrong on one out put but the other thing is once i have pressed a button i would like them to be all the same thus not allowing me to do the previous ideas. so my question is how do i allow a output to multiple pins then when i press a button assign it to display opposing colours i am currently using this code with the arduino mega  which is fine for one output.

#define GREEN 11
#define BLUE 13
#define RED 9
#define delayTime 20

void setup() {

  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);
  digitalWrite(GREEN, HIGH);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, HIGH);
}

int redVal;
int blueVal;
int greenVal;

void loop() {

  int redVal = 255;
  int blueVal = 0;
  int greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    greenVal += 1;
    redVal -= 1;
    analogWrite( GREEN, 255 - greenVal );
    analogWrite( RED, 255 - redVal );

    delay( delayTime );
  }

  redVal = 0;
  blueVal = 0;
  greenVal = 255;
  for( int i = 0 ; i < 255 ; i += 1 ){
    blueVal += 1;
    greenVal -= 1;
    analogWrite( BLUE, 255 - blueVal );
    analogWrite( GREEN, 255 - greenVal );

    delay( delayTime );
  }

  redVal = 0;
  blueVal = 255;
  greenVal = 0;
  for( int i = 0 ; i < 255 ; i += 1 ){
    redVal += 1;
    blueVal -= 1;
    analogWrite( RED, 255 - redVal );
    analogWrite( BLUE, 255 - blueVal );

    delay( delayTime );
  }
}

Go Up