Rgb led lighting help needed

This is my code but I can’t figure out how to make it work. It says it’s ok but my Pwm outputs don’t do anything we. I need this so I can have one button make the strip fade and then a second button be one solid color

const int buttonPin1 = 2;
const int buttonPin2 = 4;
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;


int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;


void setup() {

 

}

void loop() {
 // read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
// read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);

 // check if the pushbutton is pressed.
 // if it is, the buttonState is HIGH:
 if (buttonState1 == HIGH) {
 unsigned int rgbColour[3];

 // Start off with red.
 rgbColour[0] = 255;
 rgbColour[1] = 0;
 rgbColour[2] = 0;  

 // Choose the colours to increment and decrement.
 for (int decColour = 0; decColour < 3; decColour += 1) {
   int incColour = decColour == 2 ? 0 : decColour + 1;

   // cross-fade the two colours.
   for(int i = 0; i < 255; i += 1) {
     rgbColour[decColour] -= 1;
     rgbColour[incColour] += 1;
     
     setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
     delay(5);
   }
 }
} else {unsigned int rgbColour[3];

 // Start off with red.
 rgbColour[0] = 0;
 rgbColour[1] = 0;
 rgbColour[2] = 0;  

 // Choose the colours to increment and decrement.
 for (int decColour = 0; decColour < 3; decColour += 0) {
   int incColour = decColour == 2 ? 0 : decColour + 0;

   // cross-fade the two colours.
   for(int i = 0; i < 255; i += 1) {
     rgbColour[decColour] -= 0;
     rgbColour[incColour] += 0;
     
     setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
     delay(5);}
     }
   }if (buttonState2 == HIGH){unsigned int rgbColour[3];

 // Start off with red.
 rgbColour[0] = 0;
 rgbColour[1] = 100;
 rgbColour[2] = 255;  

 // Choose the colours to increment and decrement.
 for (int decColour = 0; decColour < 3; decColour += 0) {
   int incColour = decColour == 2 ? 0 : decColour + 0;

   // cross-fade the two colours.
   for(int i = 0; i < 255; i += 1) {
     rgbColour[decColour] -= 0;
     rgbColour[incColour] += 0;
     
     setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
     delay(5);}
 }
}else {unsigned int rgbColour[3];

 // Start off with red.
 rgbColour[0] = 0;
 rgbColour[1] = 0;
 rgbColour[2] = 0;  

 // Choose the colours to increment and decrement.
 for (int decColour = 0; decColour < 3; decColour += 0) {
   int incColour = decColour == 2 ? 0 : decColour + 0;

   // cross-fade the two colours.
   for(int i = 0; i < 255; i += 1) {
     rgbColour[decColour] -= 0;
     rgbColour[incColour] += 0;
     
     setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
     delay(5);}
     }
   }
 
}
void setColourRgb( int red,  int green, int blue)
{

 analogWrite(redPin, red);
 analogWrite(greenPin, green);
 analogWrite(bluePin, blue);
}

Please read the "how to use the forum" stickies to see how to format and post code.

What does the code actually do?

If you put some Serial.prints in the code at strategic places to see what your variables are doing you might see the problem.

Do you have pulldown resistors on the switch inputs?

and do you have current limiting resistor (what value? red is usually more touchy) on the 3 pins for R G and B?

J-M-L: and do you have current limiting resistor (what value? red is usually more touchy) on the 3 pins for R G and B?

Yes 1k ohm and a tip 31

Is the Tip31 highside or lowside?

KeithRB: Is the Tip31 highside or lowside?

Low side I think.

Lowside means that the emitter is connected to ground and the collector goes to the LED.

KeithRB: Lowside means that the emitter is connected to ground and the collector goes to the LED.

I'm using common anode led strips.

Do analogWrites work if the pins are not declared as outputs?

void setup() {

 

}

I've never tried that.

How are the buttons wired? Preferred method is to declare the pins with internal pullup resistors enabled in setup(): pinMode (buttonPin, INPUT_PULLUP); the button connecting the pin to Gnd when pressed, and then check for a Low to see if the button is pressed: if (digitalRead(buttonPin) == LOW){ // pressed, do something

LED strips usually have resistors built in. Can you post a clear, up close picture of a section of the strip?

Also, see Figure 9 of the data sheet http://www.onsemi.com/pub_link/Collateral/TIP31A-D.PDF You have to drive the base pretty hard to achieve low Vce. What resistor do you have between Arduino pin and TIP31 base?

CrossRoads: Also, see Figure 9 of the data sheet http://www.onsemi.com/pub_link/Collateral/TIP31A-D.PDF You have to drive the base pretty hard to achieve low Vce. What resistor do you have between Arduino pin and TIP31 base?

1kohm

They do work if their not defined as outputs I don't know why or how. I tried putting in that they're outputs in the void setup and still nothing

One more time. How are the switches wired?

This how the switches are wired

2.png