Page 98 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 98
Chapter 4: Prog ramming the P arallax Propeller Chip 77
The referenced object file name is formally Output.spin; however, the .spin suffix is
assumed and does not need to be in the instruction, nor will it be used any further in my
discussion. LED is the internal or logical reference by which the Blinker1 program will refer
to the Output program. You might think of LED as a nickname in much the same way as you
normally refer to friends and family by their familiar names instead of their formal names.
The last section in the Blinker1 Editor area is named PUB (which is short for PUBLIC).
There is also another identifier next to PUB, which in this case is called Main. Main is the
name of a method, which is something that performs an action. It can be thought of as a
function or subroutine if that fits your experience. The method named Main, being the first
one in the program listing, is where the Spin program will start its execution. Note that by
convention only one Main method should be in a Spin program and that it is ordinarily
located in the Top Object, which is the Blinker1 program. Naming the starting method Main
is not mandatory but it does make reading Spin code much easier. I will discuss two
statements in the Main method separately, but you must first realize that neither one will
make much sense until you read the section below on the Output program. For right now,
just continue reading, and I assure you that the material will become clearer as you finish
reading all of it. Another point to remember is that several PUB sections may be in a Spin
program and that each one contains its own method. How they are sequenced usually makes
no difference except that if the Main method exists in a file, it should be first.
The first program instruction in the Blinker1’s Main method is:
LED.Start(14, 6_000_000, 20)
The instruction is in an OO structure in which the reference name LED is to the left of the ‘.’,
which in OO terminology is known as the “member of” operator. I will simply refer to this
term as “dot” from now on. The name “Start”, which is directly to the right of the dot
refers to a method named Start that is located and defined in the Output file. Remember that
LED is the local name or reference to Output. The three values between the parentheses
following the Start method name are arguments that are needed by Start to correctly perform
its function. Right now, I will ignore their meaning, since it is not important for this particular
discussion, but I will address it in the Output program discussion. Paraphrasing this
instruction in OO terms would lead to the following:
Execute the Start method, which is a member of the Output object, with these three
specific data values.
The next instruction in the Main method is:
LED.Toggle(15, 4_000_000, 40)
By using the same logic as above, this instruction would translate to:
Execute the Toggle method, which is a member of the Output object, with these three
specific data values.
It is now time to examine the Output file Spin code so that you can fully understand
what is happening with the foregoing instructions. Figure 4.8 is a screenshot of Output’s Full
Source code view. You may notice immediately that it does not contain nearly as much
documentation and as many comments as does the Blinker1 code; nor should it, since it is a