Page 220 - The Ultimate Palm Robot
P. 220
Color profile: Generic CMYK printer profile
Composite Default screen
Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
Chapter 8 Taking Control of the BrainStem Robot 203
Recall that this means the main( ) function takes no arguments and returns no
values. However, in TEA the main( ) function can also have a return type of
char or int, and it can take an arbitrary number of parameters. Within main( ),
you can execute program logic and call other functions or subroutines. These
functions and subroutines can be in the same file, or they can be included from
other files.
Just as with C or C++, you can include other source files using the #include
macro:
#include <aPPRK.tea>
The command shown above includes the named source file, aPPRK.tea,
into the current source file. Recall that with TEA programs, the file you in-
clude, aPPRK.tea for example, is a source code file, and not a header file. Code
in the current source file can call any of the functions or subroutines defined in
the included file.
Subroutines and functions are code modules that can be called just like
functions and subroutines in C. The primary difference between the functions
and subroutines is that functions return a value and subroutines do not.
int myFunction() /* returns an int */
void mySubroutine() /* returns nothing (void) */
A Sample TEA Program
IfyouwentthroughChapter5,youhavealreadyencounteredoneTEAprogram,
simple.tea. This is the program that waits until sensor 1 detects an object, and
then it does a little jig that consists of moving away from the object, turning
one direction, then reversing the turn, and finally moving forward.
Rather than go through that code again, let’s examine another of the TEA
sample programs and look a little more closely at how it works. After we do
that, you may want to investigate the other sample programs on your own or
try writing a TEA program yourself.
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:44 PM