122-32000 Parallax Inc, 122-32000 Datasheet - Page 110

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
Exercise 6: Output.spin & Blinker1.spin – Using Our Object
Now let’s explore the power of objects. All of the preceding exercises created an application
that contained only one object; the Output.spin object is the entire application. This is typical
of how new objects begin their development. Suppose that the motivation behind all this
work was really to create an object other developers could use to easily toggle one or more
I/O pins. Yes, it may be silly to create an object for such a use, but let’s have fun with it
anyway!
It’s time to make our Output object easily interface with other objects. Edit your code to look
like the following:
Example Object: Output.spin
{{ Output.spin }}
Toggle two pins, one after another.}}
VAR
PUB Main
PUB Start(Pin, Delay, Count)
{{Start new toggling process in a new cog.}}
PUB Toggle(Pin, Delay, Count)
{{Toggle Pin, Count times with Delay clock cycles in between.}}
Be sure to save this object with the filename “Output.spin” for later use by our next object.
Page 110 · Propeller Manual v1.0
long Stack[9]
cognew(Toggle(16, 3_000_000, 10), @Stack)
Toggle(17, 2_000_000, 20)
cognew(Toggle(Pin, Delay, Count), @Stack)
dira[Pin]~~
repeat Count
!outa[Pin]
waitcnt(Delay + cnt)
'Stack space for new cog
'Set I/O pin to output direction
'Repeat for Count iterations
' Toggle I/O Pin
' Wait for Delay cycles
'Toggle P16 ten…
'Toggle P17 twenty…

Related parts for 122-32000