27220 Parallax Inc, 27220 Datasheet - Page 109

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
' -----[ Program Code ]----------------------------------------------------
Main:
' -----[ Subroutines ]-----------------------------------------------------
Wait_For_Count:
Behind the Scenes
The purpose of the Wait_For_Count subroutine is to cause the program to wait
for a specified number of events. In an industrial setting, for example a packaging
system, we might need to run a conveyor belt until 100 boxes pass a sensor.
As you can see we’ve built upon the “pro” technique explored in the previous
chapter. At the top of the loop the input state is captured in nScan, and then
compared to the previous state (oScan) to detect a change (saved in xScan).
When the input has changed from ‘0’ to ‘1’ between scans the event count is
updated and displayed. The reason for capturing the input before the comparison is
to prevent the possibility of being affected by an input state change while processing
the comparison line.
Note that displaying the current event count in the middle of the Wait_For_Count
subroutine does put a limit on the rate of change the subroutine can accommodate.
DEBUG CLS,
target = 25
GOSUB Wait_For_Count
DEBUG "Count complete."
END
DO
LOOP UNTIL (eCount = target)
RETURN
nScan = EventIn
xScan = nScan ^ oScan & nScan
oScan = nScan
IF (xScan = 1) THEN
ENDIF
eCount = eCount + 1
DEBUG CRSRXY, 0, 1,
"Started...", CR
"Count = ", DEC eCount, CR
' set target value
' wait for 25 pulses
' capture input
' look for 0 -> 1 change
' save this scan
' add new event

Related parts for 27220