27297 Parallax Inc, 27297 Datasheet - Page 109

KIT STAMPWORKS WITH BS2-IC

27297

Manufacturer Part Number
27297
Description
KIT STAMPWORKS WITH BS2-IC
Manufacturer
Parallax Inc
Datasheet

Specifications of 27297

Lead Free Status
Contains lead
Product
Microcontroller Accessories
Lead Free Status / Rohs Status
Lead free / RoHS Compliant

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
27297SQ
Manufacturer:
NS
Quantity:
4
' -----[ 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 27297