Data Sheet

Core Spartan Documentation Modern Robotics, Inc
Version 3.0.3 Page 20
5.6. Add your own functions
Using a user function can really help clean up code or help in using complex algorithms. All
user functions must be declared after the loop and can be any type (void, int, char, etc). For
example, in the example GetInfo.ino there is a custom function placed after the loop.
void cls (void){
int counter = 100;
while(counter--) Serial.print("\n");
}
This function is called inside the loop making user functions clean and easier to dissect. This
will be helpful later for debugging or improvement of the program.
void loop(){
cls();
…. more code ….
}
Without making the user function the loop would contain the code that was inside the
function resulting in the loop looking like the following.
void loop(){
int counter = 100;
while(counter--) Serial.print("\n");
…. more code ….
}
Please refer to the GetInfo.ino example for more information. In the example you can copy
the contents of the user function and place it where the cls() function is called and run it to
demonstrate that it can work either way.