How is this function called?

Hello,

i am looking for a way to set multiple outputs in one line
i have now this line that is repeating

digitalWrite(whitePin, HIGH);
digitalWrite(greenPin, HIGH);
lcd.print("message");

but i want to do something like this

set This
{
digitalWrite(whitePin, HIGH);
digitalWrite(greenPin, HIGH);
lcd.print("message");
}

do.This

but first of all, how is this called?? ( so i can find more info about it on google )

rogierv:
Hello,

i am looking for a way to set multiple outputs in one line
i have now this line that is repeating

digitalWrite(whitePin, HIGH);

digitalWrite(greenPin, HIGH);
lcd.print("message");




but i want to do something like this


set This
{
digitalWrite(whitePin, HIGH);
digitalWrite(greenPin, HIGH);
lcd.print("message");
}

do.This




but first of all, how is this called?? ( so i can find more info about it on google )

First define the function either before the startup function or after the loop function:

void This(void)   // this defines a function called This that performs the statements below
  {
   digitalWrite(whitePin, HIGH);
   digitalWrite(greenPin, HIGH);
   lcd.print("message");
  }

// then anywhere in your sketch you want to execute it just have a:
  This();  // this will execute the code in the This function

Lefty

This is a C function

void doThis()
{
  digitalWrite(whitePin, HIGH);
  digitalWrite(greenPin, HIGH);
  lcd.print("message");
}

loop()
{
  doThis();
}

Thanks too all!!!

O and a if i put this on on tab and inlcude this then, is that "good" programming to keep it clear?

rogierv:
O and a if i put this on on tab and inlcude this then, is that "good" programming to keep it clear?

It kind of depends on how many user functions you create and if there is any logical relationship among the functions. Say if you needed to write 6 functions to support a external A/D converter chip they might very well be placed into there own separate tabbed edit file, and another set of user functions to support a external D/A converter chip placed in yet another tabbed edit file. That makes it handy to just cut and paste selective logical group of user functions that you can paste into some new sketch project in the future. By the way you do not have to 'include' the tabbed file into your main sketch, the Arduino IDE pre-compiler will append them to the main sketch before sending it off to the compiler factory.

The C++ gurus around here would probably say you are better off building a class library for such grouping of related functions so you can import them into any sketch easily from a common user's library directory. Then you can use the IDE's import library menu when creating any sketch. but I'm just a simple 'C' kind of guy, so simple functions work fine for me.

If you just have a say 4 or 5 random purpose user functions that are pretty much unique to that single sketch project, you are probably best off to just place them after the loop() function, at least that is my style.

Lefty