Arduino Counting While Counting

I am extremely new to programming and wanted to work with a grid which displays LEDs going from left to right along each row and down each column one at a time. I’ve made the circuit board and had a try at the code, however I am confusing myself. I would like to count from down from 12 to 4, but after each count I want to call a new count which counts from 4 to 0. Did I do this correctly?

HectorKochFinalProject.ino (617 Bytes)

Final Project.pdf (18.2 KB)

I’ve added some comments to your code below:

``````// assign pins 0 through 12
int i;
int l;
// Count for P2
for(i=0;i<=4;i++);  // you can't have command like this outside a function
// Count for P1
for(l=5;<=12;kl++);  // ditto, also these do nothing. And what's that letter k doing there?

void setup() {
// Set pins to outputs
pinMode(i, OUTPUT): //I think these should have been inside the for-loop you attempted above. Also, that's a colon - should be a semicolon
pinMode(l, OUTPUT); // also be careful using pins 0 and 1 because they are connected to USB serial.
}

// the loop routine runs over and over again forever:
void loop() {
// First loop for P1
for(l=12,l>=8,l--);  //They shouldn't be commas and you don't want that semicolon at the end
{
digitalWrite(l, HIGH);
delay(2500);
digitalWrite(l, LOW);
// The loop for P2 after each consequetive count from P1
for(i=o,i<=4,i++)   //again these shouldn't be commas, and that should be a zero not a lower case O
{
digitalWrite(i, HIGH);
delay(500);
digitalWrite(i, LOW);
}
}
}
``````

Referring to the Original Post …

In this line

``````for(i=o,i<=4,i++)
``````

you have an ‘o’ when I think you meant to have a ‘0’ (zero).

And it counts from 0 to 4 whereas your text says you want to count from 4 to 0 - which would be like this

``````for(i = 4; i >= 0; i --)
``````

And note how a little white-space makes code much easier to read.

…R
Edited to change commas to semi-colons in the FOR loop

Robin - you might like to review your for loop and its use of commas ...

UKHeliBob:
Robin - you might like to review your for loop and its use of commas ...

Many thanks. I had missed that in the OP's code.

...R