Error Message, Leds, NEED HELP PLEASE

Hello, well i am eventually going to use this code to control a larger led matrix in which i need to turn on more than one led at a time, so as i understand it, the best way to do that is to blink them on and off really fast so i want to make the code to blink each one on and off an integer so i don't have to type it in alot. Also i was wondering if there was a repeat function, so i can repeat a certain string of code a few times. (Im making an analog clock)
this is the link to my original form: Arduino Forum
Well i know i am doing something wrong, i want to know how to fix it and or a better way to do it. here is the code

int led3 = 3 ;
int led4 = 4;
int n ;
int x ;

void setup() {

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}

void loop()
{
n = {
digitalWrite(3, HIGH);
delay(1000);
digitalWrite(3, LOW);
delay(1000);
}

x = {
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);
delay(1000);
n;
m;
n;
m;

}

Im getting an error message at " n = {"
arduino says the error is: expected primary expression before '{' token

Blink.cpp: In function 'void loop()':
Blink:14: error: expected primary-expression before '{' token
Blink:14: error: expected ;' before '{' token Blink:21: error: expected primary-expression before '{' token Blink:21: error: expected ;' before '{' token
Blink:31: error: expected `}' at end of input

PLEASE HELP, thanks

Im getting an error message at " n = {"
arduino says the error is: expected primary expression before '{' token

Well, of course you are. You can't assign a variable a value that is a block of code. What are you trying to assign to n?

i just want to be able to assign a set of code (turn led on, delay, turn led off) to a variable so i can just say turn "n" on for 1 sec, off 1 sec, turn "x" on 1 sec, off 1 sec then repeat a set number of times. could you help me with that. is there a different way to do that?

i just want to be able to assign a set of code (turn led on, delay, turn led off) to a variable so i can just say turn "n" on for 1 sec, off 1 sec, turn "x" on 1 sec, off 1 sec then repeat a set number of times. could you help me with that. is there a different way to do that?

Variables hold values, not blocks of code. What you want is a function that takes an argument, the time to be on or off.

hello, could you please show me how to make a function and an argument, for example a block of code on the two working together. I am 16 and learning as i go. I already learned how to build a matrix and control it but this kind of confuses me but i'm sure i can learn. thank you.

Making a function is easy. It needs a name, a return type, and some arguments with tyoes.

type functionName(argType argName, argType argName,...)
{
   // what to do
}

The block of code that you are trying to assign to n goes inside the curly braces.

It appears that you want something like:

void n()
{
  digitalWrite(3, HIGH);
  delay(1000);
  digitalWrite(3, LOW);
  delay(1000);
}

void m()
{
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  delay(1000);
}

void loop()
{
   n();
   m();
}

If you look at the two functions, you see that they are identical except for the pin number. This is where the argument comes in:

void blink(int pin)
{
  digitalWrite(pin, HIGH);
  delay(1000);
  digitalWrite(pin, LOW);
  delay(1000);
}

void loop()
{
   blink(3);
   blink(4);
}

You could, of course, extend this to make the blinking time an argument, too:

void blink(int pin, long time)
{
  digitalWrite(pin, HIGH);
  delay(time);
  digitalWrite(pin, LOW);
  delay(time);
}

void loop()
{
   blink(3, 250);
   blink(4, 500);
}

thanks so much and wow you're fast. if i was using this function: i want to flicker two light on and off (like 1 milisecond on) and then the other one on so that they both aren't on at the same time but it looks like they are and i need them to stay on for like the duration of 1 min and 1 hour so how would i repeat both functions like 36000 times or whatever it works out to be without writing it that many times.
this is the one i would like to use:

void blink(int pin)
{
digitalWrite(pin, HIGH);
delay(1000);
digitalWrite(pin, LOW);
delay(1000);
}

void loop()
{
blink(3);
blink(4);
}

THANK YOU!!

if i was using this function: i want to flicker two light on and off (like 1 milisecond on) and then the other one on so that they both aren't on at the same time but it looks like they are

You need a different function for this:

void blink2(int pin1, long time1, int pin2, long time2)
{
   digitalWrite(pin1, HIGH);
   delay(time1);
   digitalWrite(pin1, LOW);

   digitalWrite(pin2, HIGH);
   delay(time2);
   digitalWrite(pin2, LOW);
}

This way, only one pin is on at a time. The time that each pin is on is independent.

how would i repeat both functions like 36000 times or whatever it works out to be without writing it that many times.

Use a for loop. http://arduino.cc/en/Reference/For

Keep in mind that loop() is called in an infinite loop, so, when the for loop ends, loop will be called again, the blinking will start again.

well i know something is wrong here but i think i’m somewhat on my way. (although i’m probably totally wrong) So what i am trying to do is switch between two leds blinking on an off and keep one on for an hour and the other on for one min. once on min is up it switches too a new led but the hour one stays the same, and then they continue blinking really fast again. each led represents a place on an analog clock, 12 hour leds and 60 minute leds. (actually 30 minute leds, each one will count as 2 minutes) i am making a 6 by 7 matrix on my arduino uno and then wiring each led out to a certain part on a circle. so how does this code look? or after explaining all of this, is there a better way of doing it? Thanks!

void blink2(int pin1, long time1, int pin2, long time2);

void setup() {
}
  
void loop(){
   int pin1 = 1;
   int pin2 = 2;
   
   For (int i=0; i <= 3600; i++){
   {
   digitalWrite(pin1, HIGH);
   delay(2);
   digitalWrite(pin1, LOW);

   digitalWrite(pin2, HIGH);
   delay(2);
   digitalWrite(pin2, LOW);
}
   }
}

void loop(){
   int pin3 = 3;
   int pin4 = 4;
   
   For (int i=0; i <= 3600; i++){
   {
   digitalWrite(pin3, HIGH);
   delay(2);
   digitalWrite(pin3, LOW);

   digitalWrite(pin4, HIGH);
   delay(2);
   digitalWrite(pin4, LOW);
}
   }
}

You haven't even compiled that code.

what do you mean compiled? and what i was asking for was how to repeat a certain function or set of functions a given number of times

I mean you haven't pressed the verify button on the IDE.
That invokes the compiler.
This you haven't done.

You seem to be largely ignoring the suggestions made by others (and I write this in response to a personal message plea) so I don’t know if I can add much more. But to answer your specific question:

  for (int i = 0; i < 3600; i++)
    {
    blink (1234);   // do this 3600 times 
    }

You might want to look at some of the examples that came with the Arduino. For one thing, you need to set pin modes to output before trying to make them blink.

I did a post about doing blinks of multiple LEDs here:

http://gammon.com.au/blink

what do you mean compiled?

If you are going to post code, at least compile it (hit Ctrl+R in the IDE). Your code wouldn’t have compiled, so worrying about what it does is a bit secondary to getting the syntax right.

Well here it is, i think i made the basis of my clock. Could you please look over it before i need to mass duplicate it to make the rest of the minutes for 12 oclock plus the rest of the hours and minutes for 1-11. I would love a better way to do this but i don’t know how. I am trying to understand everyone elses advice but im just not understanding it. I am sorry, i couldn’t figure out how to compile the code so that isn’t done. My apologies in advance. Thanks!!

  /*
  Analog clock with an led at each number marker.
  Controled by a 6 by 7 matrix
  The first two columns represent the hours
  Column 3-7 represent the 30 minute leds, 
  */
  int rowPin1 = 13;
  int rowPin2 = 12;
  int rowPin3 = 11;
  int rowPin4 = 10;
  int rowPin5 = 9;
  int rowPin6 = 8;

  int colPin1 = 1;
  int colPin2 = 2;
  int colPin3 = 3;
  int colPin4 = 4;
  int colPin5 = 5;
  int colPin6 = 6;
  int colPin7 = 7;

void a()
{
  //this will be 12:00
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void b()
{
  //this will be 12:02
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void c()
{
  //this will be 12:04
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin3, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin3, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void d()
{
  //this will be 1:00
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void setup()
{
  pinMode(rowPin1, OUTPUT);
  pinMode(rowPin2, OUTPUT);
  pinMode(rowPin3, OUTPUT);
  pinMode(rowPin4, OUTPUT);
  pinMode(rowPin5, OUTPUT);
  pinMode(rowPin6, OUTPUT);

  pinMode(colPin1, OUTPUT);
  pinMode(colPin2, OUTPUT);
  pinMode(colPin3, OUTPUT);
  pinMode(colPin4, OUTPUT);
  pinMode(colPin5, OUTPUT);
  pinMode(colPin6, OUTPUT);
  pinMode(colPin7, OUTPUT);
  
}

void loop()
{
   a(200);
   //repeat a 200 times to equal 2 minute
   //12:00
   b(200);
   //repeat b 200 times to equal 2 minute
   //12:02
   c(200);
   //repeat c 200 times to equal 2 minute
   //12:04
}

Just out of curiosity, are you planning to make 720 functions to handle all of the 720 lots of 2 minute intervals in a day?

technically it would only be 360 but yes, i was planning on that..... now that you mention it, that is alot of code. I don't know a better way of doing it. I am very confused by every ones guidance besides Paul S, his code examples helped me alot. So unless you can come up with a better method, PLEASE, that is what i was going to do........ and i'm sorry if i seem useless with directions and instructions but im new.

I tried verifying the code and i got the error "too many arguments to function 'void a()' . what does this mean and how can i fix it?

CLOCKY.cpp: In function 'void loop()':
CLOCKY:21: error: too many arguments to function 'void a()'
CLOCKY:106: error: at this point in file
CLOCKY:37: error: too many arguments to function 'void b()'
CLOCKY:109: error: at this point in file
CLOCKY:53: error: too many arguments to function 'void c()'
CLOCKY:112: error: at this point in file

  /*
  Analog clock with an led at each number marker.
  Controled by a 6 by 7 matrix
  The first two columns represent the hours
  Column 3-7 represent the 30 minute leds, 
  */
  int rowPin1 = 13;
  int rowPin2 = 12;
  int rowPin3 = 11;
  int rowPin4 = 10;
  int rowPin5 = 9;
  int rowPin6 = 8;

  int colPin1 = 1;
  int colPin2 = 2;
  int colPin3 = 3;
  int colPin4 = 4;
  int colPin5 = 5;
  int colPin6 = 6;
  int colPin7 = 7;

void a()
{
  //this will be 12:00
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void b()
{
  //this will be 12:02
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void c()
{
  //this will be 12:04
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin3, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin3, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void d()
{
  //this will be 1:00
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void setup()
{
  pinMode(rowPin1, OUTPUT);
  pinMode(rowPin2, OUTPUT);
  pinMode(rowPin3, OUTPUT);
  pinMode(rowPin4, OUTPUT);
  pinMode(rowPin5, OUTPUT);
  pinMode(rowPin6, OUTPUT);

  pinMode(colPin1, OUTPUT);
  pinMode(colPin2, OUTPUT);
  pinMode(colPin3, OUTPUT);
  pinMode(colPin4, OUTPUT);
  pinMode(colPin5, OUTPUT);
  pinMode(colPin6, OUTPUT);
  pinMode(colPin7, OUTPUT);
  
}

void loop()
{
   a(200);
   //repeat a 200 times to equal 2 minute
   //12:00
   b(200);
   //repeat b 200 times to equal 2 minute
   //12:02
   c(200);
   //repeat c 200 times to equal 2 minute
   //12:04
}

One is too many, if the specified number is zero.
If you want a function to take arguments, you have to let the compiler know about them.

So is this the way to do it then? I know something is wrong cause i'm getting an error message. also, is there a better way of doing this whole code so i don't have to make like 300 functions?

Error: variable or field 'loop' declared void
for some reason it highlights this line of text>>> Column 3-7 represent the 30 minute leds,

  /*
  Analog clock with an led at each number marker.
  Controled by a 6 by 7 matrix
  The first two columns represent the hours
 [glow=yellow,2,300] Column 3-7 represent the 30 minute leds,[/glow] 
*/
  
  int rowPin1 = 13;
  int rowPin2 = 12;
  int rowPin3 = 11;
  int rowPin4 = 10;
  int rowPin5 = 9;
  int rowPin6 = 8;

  int colPin1 = 1;
  int colPin2 = 2;
  int colPin3 = 3;
  int colPin4 = 4;
  int colPin5 = 5;
  int colPin6 = 6;
  int colPin7 = 7;

void a()
{
  //this will be 12:00
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void b()
{
  //this will be 12:02
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void c()
{
  //this will be 12:04
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin3, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin3, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void d()
{
  //this will be 1:00
  digitalWrite(rowPin2, HIGH);
  digitalWrite(colPin1, LOW);
  delay(5);
  digitalWrite(rowPin2, LOW);
  digitalWrite(colPin1, HIGH);
  digitalWrite(rowPin1, HIGH);
  digitalWrite(colPin3, LOW);
  delay(5);
  digitalWrite(rowPin1, LOW);
  digitalWrite(colPin3, HIGH);
  
}

void setup()
{
  pinMode(rowPin1, OUTPUT);
  pinMode(rowPin2, OUTPUT);
  pinMode(rowPin3, OUTPUT);
  pinMode(rowPin4, OUTPUT);
  pinMode(rowPin5, OUTPUT);
  pinMode(rowPin6, OUTPUT);

  pinMode(colPin1, OUTPUT);
  pinMode(colPin2, OUTPUT);
  pinMode(colPin3, OUTPUT);
  pinMode(colPin4, OUTPUT);
  pinMode(colPin5, OUTPUT);
  pinMode(colPin6, OUTPUT);
  pinMode(colPin7, OUTPUT);
  
}

  void loop(200)
{
   a();
   //repeat a 200 times to equal 2 minute
   //12:00
}
  void loop(200)
{
   b();
   //repeat b 200 times to equal 2 minute
   //12:02
}
  
  void loop(200)
{
   c();
   //repeat c 200 times to equal 2 minute
   //12:04
}

No, loop doesn’t take arguments either.
You should NEVER call loop directly