Hi guys, first post.
I have trawled the web and just cant find a simple, definitive answerer/solution to my problem.
I have 20 LEDs connected in 2 coloums(by the cathodes) x 10 Rows of 2(by their anodes).
I have the following code(which will be hideously inefficient);
int Rows[10] = {2, 5, 4, 6, 7, 9, 8, 10, 12, 11}; //Create an array of pins
int pinCount = 10;
int cathA = 3; //Declare pin 3 as cathode A
int cathB = 13; //Declare pin 13 as cathode B
void setup() {
Serial.begin(9600); //Open serial port at 9600 baud (just in case)
for (int thisRow = 0; thisRow < pinCount; thisRow++) { //Incriment the pins used and set them as outputs
pinMode(Rows[thisRow], OUTPUT);
}
pinMode(cathA, OUTPUT); //Declare cathode A as output
pinMode(cathB, OUTPUT); //Declare cathode B as output
digitalWrite(cathA, HIGH); //Set cathode A pin high (turns off cathA column)
digitalWrite(cathB, HIGH); //Set cathode B pin high (turns off cathB column)
for (int thisRow = 0; thisRow < pinCount; thisRow++) { //Incriment the pins used
digitalWrite(Rows[thisRow], LOW); //Turn off all LEDs
}
}
void loop() {
/* **********************************************************************************************************************
***********************************************************************************************************************/
//PATTERN 1 //Makes LED chaser up column A and down column B
int i=0; //Create counter i and initialize to 0
while (i<=10){ //Create a while loop to run trhough pattern 1 10 times
digitalWrite(cathA, LOW); //Ground the cathode A pin by sending it low
for (int thisRow = 0; thisRow < pinCount; thisRow++) { // loop from the lowest pin to the highest:
digitalWrite(Rows[thisRow], HIGH); // turn the pin on:
delay(70); //pause
digitalWrite(Rows[thisRow], LOW); // turn the pin off:
}
digitalWrite(cathA, HIGH); //Send cathA HIGH to turn off column
delay(10);
digitalWrite(cathB, LOW); //Take cathB LOW to ground column
for (int thisRow = pinCount - 1; thisRow >= 0; thisRow--) { //Then loop from the highest pin to the lowest:
digitalWrite(Rows[thisRow], HIGH); // turn the pin on:
delay(70); //'pause
digitalWrite(Rows[thisRow], LOW); // turn the pin off:
}
digitalWrite(cathB, HIGH); //Send cathB HIGH again to turn off column
delay(10);
i=i+1; //Add 1 to the count
}
delay(1000);
/**********************************************************************************************************************
***********************************************************************************************************************/
//PATTERN 2 //Makes 2 column LED chaser
i=0; //Reset counter i to 0
while (i<=10){ //Create while loop
digitalWrite(cathA, LOW); //Ground the cathode A pin by sending it low
digitalWrite(cathB, LOW); //Ground the cathode B pin by sending it low
for (int thisRow = 0; thisRow < pinCount; thisRow++) { // loop from the lowest pin to the highest:
digitalWrite(Rows[thisRow], HIGH); // turn the pin on:
delay(70);
digitalWrite(Rows[thisRow], LOW); // turn the pin off:
}
for (int thisRow = pinCount - 1; thisRow >= 0; thisRow--) { //Then loop from the highest pin to the lowest:
digitalWrite(Rows[thisRow], HIGH); // turn the pin on:
delay(70);
digitalWrite(Rows[thisRow], LOW); // turn the pin off:
}
i=i+1;
}
}
(hope the html code tag is acceptable?)
What I am trying to do now is write to every other pin of the array. So a counter that starts at index 0 and skips next pin, writes to index 2(which is LED3) skips one, writes to 4 etc etc, then the same thing but starting at index 1, skip one, go to index 3, skip one, etc. Do you follow what I mean?
What Ive tried(other than days of fruitless googling);
for (int thisRow = 0; thisRow<pinCount; thisRow +2){
digitalWrite(Rows[thisRow], HIGH);
}
This obviously didnt work. Then I tried
digitalWrite(Rows[0,2,4,6,8], HIGH);
And that didnt work either.
So please, I ask for your help....how do I create a for loop (or function) to increment through every other pin? (if it's possible...it must be).
Thank you for your time, I hope the format of the post is ok.
ps, I am very, very new to arduino and code, so baby talk please. Cheers all.