Go Down

Topic: Why doesn't my function work ? (Read 446 times) previous topic - next topic

Skamajster

Apr 07, 2013, 12:47 pm Last Edit: Apr 07, 2013, 12:53 pm by Skamajster Reason: 1
Hi! I am a newbie programmer, and i have a simple question. I would like to make my project and simplify it by splitting it in external functions.

But i have problem, because this functions does not change the value of variables or write something in serial monitor. Why? There is a simple example:


Code: [Select]

 int variable = 15;
 
 void function()
   {
   Serial.println("I like green tea.");
   variable = 420;
   delay(10000);
   }
   

 void setup ()
 {
  Serial.begin(9600);
 }

 void loop()
 {
  void function();
  Serial.println(variable);
  delay (1000);
 }



It seems that this "function" don't work. Why? I read some articles, but i couldn't find solution myself. Thanks for help!

AWOL

#1
Apr 07, 2013, 12:49 pm Last Edit: Apr 07, 2013, 12:51 pm by AWOL Reason: 1
For a function to work, you have to call it, not provide a prototype.

"delay()" is also a void function.
Can you see how it is called is different to how you've tried to call your function?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

michinyon


michinyon

If you wish to invoke the function,  you need code like...
Code: [Select]


void loop()
{
    function() ;   // this calls the function
    // ... other stuff
}

Skamajster

Thank you very much! This was so easy, and i tried to repair it all the yesterday evening. Stupid me :).

Go Up