When I upload it to the Arduino, I just prints "connecting...." and it doesn't execute the functions that I have called in the "void loop()". Any suggestions on what is wrong with the code? Thank You
K&R still on of the best books I have on C
But prototypes are normally put in the include file. It tells the compiler that it will encounter a function meeting the specifications of the prototype. But basically you can put them anywhere as long as they appear before the actual function shows up in the compiler. The Arduino IDE actually generates the prototypes (to my understanding) but if you use for example Eclipse, you have to define them yourself.
In you case the prototypes are defined in the loop. So no actual function is called.
holmes4:
What use would a prototype be at that point in the code?. I can't see a possible use and therefore would expect and error message.
The great thing about C++ is, if its allowed, there is usually a reason for it, even if its something really obscure.
Now with function prototypes, every one sees them as 'global' entities, and as such take the global scope for granted.
But prototypes follow the standard scope rules: "the prototype is only usable within the scope it has been declared in".
Maybe it can be seen as a "private non-member non-static function" ( no class ).
This sketch shows this effect:
#include "Arduino.h"
#ifdef DO_NOT_COMPILE
//C++ will not see this prototype.
//This is here to prevent the Arduino IDE from outputting its own prototype.
void func();
#endif
void setup() {
Serial.begin( 9600 );
void func();
func(); //Works fine.
}
void loop() {
func(); //Error, cannot see prototype.
}
void func(){ Serial.println( "Call" ); }