Writing a function "FAILURE!"

Why is it that the declaration of some user defined "function names" are accepted by the IDE, and others are not? It is my understanding that the "function name" is supposed to turn orange when placed after the "void", yet, only some of my function names do; and, if they don't change color, they will not work, even if the code within them is flawless. Thoughts? See example code:

void blink(int On,int Off){  //this "function" works
    digitalWrite(13, HIGH);
    delay(On);
    digitalWrite(13, LOW);
    delay(Off);}
    
void green(){                //this "function" does not work
    digitalWrite(12, HIGH);} //this code works if used on its own. A green LED is tied to this pin.

In my IDE, the word "blink" is orange, and, the word "green" is not. There is technically no difference between the two functions, but, the "blink" function works and the "green" function doesn't.

Orange means that it's a keyword which the IDE recognises. It means it already does something else. You should not use those words for your own functions. You can't call a function while() or if() or true().

Note that individual libraries can also define keywords and they will show up in orange too.

What doesn't work with the green() function? There must be something else wrong in the code you didn't show us.

Dcells:
In my IDE, the word "blink" is orange, and, the word "green" is not. There is technically no difference between the two functions, but, the "blink" function works and the "green" function doesn't.

What you see with the "green" function is the normal case. And of course, that function will work correctly when used correctly.

If the identifier name turns orange this means: You have installed a library along with a "keywords.txt" file, which defines the identifier name as a "keyword" for this library.

If you use the same identifier name in your sketch, you might get into trouble if you want to include and use that other library, which already has a 'blink' identifier defined for usage in the library.

So for your own identifier names like variable names or function names you better avoid all names that suddenly turns into orange. You better only use those names if you actually want to use the class, variable or function from the library which defined that identifier name.

If I call the "green" function from elsewhere in my code, nothing happens. However, if I take the code within the function and use it where the call was, it works.

MorganS,
"Keyword" reference aside, [because it makes sense that someone would have created a library reference for the "Blinking LED function" by now] why does the code within the function work, but, the function does not? It is a simple LED circuit that is tied to digital pin 12. Nothing is left out. It completely defies logic. Pardon the pun.

I think that the problem is on line 42 of the code that I can't see. :slight_smile:

Dcells:
why does the code within the function work, but, the function does not?

Is the function called? Or is it just declared?

Where is the function call - I cannot see the sketch code!

jurs,
The "function call" is resident within an "if-else" function and is relevant to a button push. If the button is pushed, condition is true, and the "function" should react.

It is my understanding that the "function name" is supposed to turn orange when placed after the "void",

Your understanding is wrong.

void green(){ //this "function" does not work
digitalWrite(12, HIGH);} //this code works if used on its own. A green LED is tied to this pin.

So ? It works or it doesn't? How would you ever turn it off ?