I am very new to the C language and I am having troubles calling individual LED's. I have pulled down some code off-line and added some buttons. The project is a 3rd brake light and using the RGB to change it to mini light bar. I am only using Red and Blue. I have managed to eek my way through but I am having difficulty with controlling each LED individually. I tried a digitalWrite in a void at the bottom of the void loop but it only writes the first block of blueLED's. I was trying to get it to scroll in the opposite direction as well, which did not work. I need a little guidance with one or two of the LED's and I will add the rest of the code. I know delay is evil but I thought I could get away with it. Having the redLED's go on solid after the 3rd blink would be a plus. I am using common anode LED's if that makes a difference?
Thanks in advance because I am coming from old school line number basic background with goto's and gosub's and not used to having just one loop and unfamiliar syntax.
int blueLED1 = 2;
int blueLED2 = 4;
int blueLED3 = 6;
int blueLED4 = 8;
int blueLED5 = 10;
int blueLED6 = 12;
int blueLED7 = A0;
int blueLED8 = A2;
int redLED1 = 3;
int redLED2 = 5;
int redLED3 = 7;
int redLED4 = 9;
int redLED5 = 11;
int redLED6 = 13;
int redLED7 = A1;
int redLED8 = A3;
int button =A5;
int button2= A4;
int i=75;
int count=0;
void setup()
{
Serial.begin(9600);
pinMode(redLED1, OUTPUT);
pinMode(redLED2, OUTPUT);
pinMode(redLED3, OUTPUT);
pinMode(redLED4, OUTPUT);
pinMode(redLED5, OUTPUT);
pinMode(redLED6, OUTPUT);
pinMode(redLED7, OUTPUT);
pinMode(redLED8, OUTPUT);
pinMode(blueLED1, OUTPUT);
pinMode(blueLED2, OUTPUT);
pinMode(blueLED3, OUTPUT);
pinMode(blueLED4, OUTPUT);
pinMode(blueLED5, OUTPUT);
pinMode(blueLED6, OUTPUT);
pinMode(blueLED7, OUTPUT);
pinMode(blueLED8, OUTPUT);
pinMode(button,INPUT);
pinMode(button2,INPUT);
}
void loop()
{
// RED BUTTON ROUTINE
if(digitalRead(button) ==HIGH)
{setColor(0, 0, 255);
}
else{setColor(255,255,255);}
// BLUE BUTTON ROUTINE
if(digitalRead(button2) ==HIGH)
{ setColor(255,0,0);delay(20);setColor(255,255,255);delay(20);
setColor(0,0,255);delay(20);setColor(255,255,255);delay(20);}
else
{ setColor(255,255,255); }
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redLED1, redValue);
analogWrite(redLED2, redValue);
analogWrite(redLED3, redValue);
analogWrite(redLED4, redValue);
analogWrite(redLED5, redValue);
analogWrite(redLED6, redValue);
analogWrite(redLED7, redValue);
analogWrite(redLED8, redValue);
analogWrite(blueLED1, blueValue);
analogWrite(blueLED2, blueValue);delay(20);
analogWrite(blueLED3, blueValue);delay(20);
analogWrite(blueLED4, blueValue);delay(20);
analogWrite(blueLED5, blueValue);delay(20);
analogWrite(blueLED6, blueValue);delay(20);
analogWrite(blueLED7, blueValue);delay(20);
analogWrite(blueLED8, blueValue);delay(20);
analogWrite(blueLED8, blueValue);delay(20);
analogWrite(blueLED7, blueValue);delay(20);
analogWrite(blueLED6, blueValue);delay(20);
analogWrite(blueLED5, blueValue);delay(20);
analogWrite(blueLED4, blueValue);delay(20);
analogWrite(blueLED3, blueValue);delay(20);
analogWrite(blueLED2, blueValue);delay(20);
analogWrite(blueLED1, blueValue);delay(20);
}