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

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 4: Output.spin – Parameters, Calls, and Finite Loops
Our current object from Exercise 3 is interesting, but still isn’t very flexible; after all, the
Toggle
more flexible and also give it the ability to toggle a specific, finite number of times. Look at
the following example and edit your code to match. We’ve crossed out the elements that
should be removed, and highlighted every new element.
{{Output.spin
Toggles Pin with Delay clock cycles of high/low time.}}
Toggles two pins, one after another.}}
CON
PUB Main
PUB Toggle(Pin, Delay, Count)
''Toggle Pin forever
{Toggles I/O pin given by Pin and waits Delay system clock cycles
in between each toggle.}
{{Toggle Pin, Count times with Delay clock cycles in between.}}
Compile and download this application to see the results. The LED on pin 16 should blink
five times (10 toggles) with 1/4th second durations and intervals, then it will stop and the
LED on pin 17 will blink ten times (20 toggles) at 1/6th second durations and intervals.
In this example we removed the constant (
made some minor modifications to the
actual pin-toggling action, but the
Page 104 · Propeller Manual v1.0
Pin
Delay = 3_000_000
Toggle(16, 3_000_000, 10) 'Toggle P16 ten times, 1/4 s each
Toggle(17, 2_000_000, 20) 'Toggle P17 twenty times, 1/6 s each
dira[Pin]~~
repeat Count
!outa[Pin]
waitcnt(Delay + cnt)
method only works with a specific pin and delay. Let’s make the
= 16
Main
Toggle
{ I/O pin to toggle on/off }
{ On/Off Delay, in clock cycles}
'Set I/O pin to output direction
'Repeat for Count iterations
' Toggle I/O Pin
' Wait for Delay cycles
method tells it when and how to do so.
CON
method. The
) block, added a new method called
Toggle
method still performs the
Toggle
Main
method
, and

Related parts for 122-32000