call block?

Im curious why there is no ability to ceate a block of code and asign it a call variable(blockx)? then summon it with a call to that variable. Perhaps it would live in the setup section of the scetch?

ex.

call DriveForward
{
  digitalWrite (EnableMotor1, LOW);
  digitalWrite (EnableMotor2, LOW);
  digitalWrite (EnableMotor1, HIGH);
  digitalWrite (EnableMotor2, HIGH);
  digitalWrite (Motor1_dir_pin, HIGH);
  analogWrite (Motor1_PWM_pin, Speed);
  digitalWrite (Motor2_dir_pin, HIGH);
  analogWrite (Motor2_PWM_pin, Speed);
}

then to call the block within the loop, perhaps something like this?

call DriveForward;

I may be missing a way to do this as I am still new to arduino. If not, this is a great tool for cleaning up scripts and saving lots of time progrmming those redundant blocks. :-?

See:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1269167796

You don't need the "call", but you do need those paretheses.

Not really a bug: this should go in "Syntax and programs"

It's called a function.

Check out a C programming tutorial.

-j

Sorry for posting in wrong forum, I was thinking along the lines of this being a suggestion for future releases of the arduino sketch software, for those of us not conversant in C.

That said, please move this thread where it belongs mr. moderator.

Thanks for the link. :slight_smile:

Since this thread is already here, I might as well see if I can get some resolution on this subject.

That said, would ths be right? I will experiment on my own shortly.

void DriveForward()
{
  digitalWrite (EnableMotor1, LOW);
  digitalWrite (EnableMotor2, LOW);
  digitalWrite (EnableMotor1, HIGH);
  digitalWrite (EnableMotor2, HIGH);
  digitalWrite (Motor1_dir_pin, HIGH);
  analogWrite (Motor1_PWM_pin, Speed);
  digitalWrite (Motor2_dir_pin, HIGH);
  analogWrite (Motor2_PWM_pin, Speed);
}

Then to call;

DriveForward;

Is this correct? That other post was a bit confusing. My appologies, I'm obviously still rather n00btastic.

Code:
DriveForward;

Is this correct?

Did you read reply #1 and the linked thread?
You need the parentheses.

I looked but did not see. The parentheses must follow the call?

DriveForward();

Right? Thank's for your patience btw.