Hello, I am trying to program a simple light show for christmas, and i am running into a series of problem. I have 12 12V LED strips being controlled by an arduino mega, and some strips have one color on no matter what i do short of unplugging it. I have narrowed down the problem to something with the arduino, and i have confirmed that it is not wiring. I have posted the code and diagrams below. Thank you for all and any help.
Code:
#define cr1 4
#define cg1 3
#define cb1 2
#define cr2 5
#define cg2 6
#define cb2 7
#define cr3 8
#define cg3 9
#define cb3 10
#define cr4 11
#define cg4 22
#define cb4 23
#define cr5 24
#define cg5 25
#define cb5 26
#define cr6 27
#define cg6 28
#define cb6 29
int state;
void setup() {
Serial.begin(115200);
pinMode(cr2, OUTPUT);
pinMode(cr3, OUTPUT);
pinMode(cr1, OUTPUT);
pinMode(cb2, OUTPUT);
pinMode(cb3, OUTPUT);
pinMode(cb1, OUTPUT);
pinMode(cg2, OUTPUT);
pinMode(cg3, OUTPUT);
pinMode(cg1, OUTPUT);
Serial.println("Outputs Set");
}
void ledstrip(int strng, int cr, int cg, int cb) {
if (strng == 1) {
if (cr == 1) {
digitalWrite(cr1, HIGH);
} else if (cr == 0) {
digitalWrite(cr1, LOW);
}
if (cg == 1) {
digitalWrite(cg1, HIGH);
} else if (cg == 0) {
digitalWrite(cg1, LOW);
}
if (cb == 1) {
digitalWrite(cb1, HIGH);
} else if (cb == 0) {
digitalWrite(cb1, LOW);
}
} else if (strng == 2) {
if (cr == 1) {
digitalWrite(cr2, HIGH);
} else if (cr == 0) {
digitalWrite(cr2, LOW);
}
if (cg == 1) {
digitalWrite(cg2, HIGH);
} else if (cg == 0) {
digitalWrite(cg2, LOW);
}
if (cb == 1) {
digitalWrite(cb2, HIGH);
} else if (cb == 0) {
digitalWrite(cb2, LOW);
}
} else if (strng == 3) {
if (cr == 1) {
digitalWrite(cr3, HIGH);
} else if (cr == 0) {
digitalWrite(cr3, LOW);
}
if (cg == 1) {
digitalWrite(cg3, HIGH);
} else if (cg == 0) {
digitalWrite(cg3, LOW);
}
if (cb == 1) {
digitalWrite(cb3, HIGH);
} else if (cb == 0) {
digitalWrite(cb3, LOW);
}
} else if (strng == 4) {
if (cr == 1) {
digitalWrite(cr4, HIGH);
} else if (cr == 0) {
digitalWrite(cr4, LOW);
}
if (cg == 1) {
digitalWrite(cg4, HIGH);
} else if (cg == 0) {
digitalWrite(cg4, LOW);
}
if (cb == 1) {
digitalWrite(cb4, HIGH);
} else if (cb == 0) {
digitalWrite(cb4, LOW);
}
} if (strng == 5) {
if (cr == 1) {
digitalWrite(cr5, HIGH);
} else if (cr == 0) {
digitalWrite(cr5, LOW);
}
if (cg == 1) {
digitalWrite(cg5, HIGH);
} else if (cg == 0) {
digitalWrite(cg5, LOW);
}
if (cb == 1) {
digitalWrite(cb5, HIGH);
} else if (cb == 0) {
digitalWrite(cb5, LOW);
}
} if (strng == 6) {
if (cr == 1) {
digitalWrite(cr6, HIGH);
} else if (cr == 0) {
digitalWrite(cr6, LOW);
}
if (cg == 1) {
digitalWrite(cg6, HIGH);
} else if (cg == 0) {
digitalWrite(cg6, LOW);
}
if (cb == 1) {
digitalWrite(cb6, HIGH);
} else if (cb == 0) {
digitalWrite(cb6, LOW);
}
} else Serial.println("Error, Uknown Strip Number");
}
void ledclear() {
ledstrip(1, 0, 0, 0);
ledstrip(2, 0, 0, 0);
ledstrip(3, 0, 0, 0);
ledstrip(4, 0, 0, 0);
ledstrip(5, 0, 0, 0);
ledstrip(6, 0, 0, 0);
}
void loop() {
}
Diagram.
Note the led strips are represented by the LED, and the battery represents 12 V.