© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 9 of 52
' bright edges, displaying them graphically using DEBUG. Finally it
' computes both the area and extent of the object found.
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
ao PIN 0 'TSL1401R's analog output (threhsolded by Stamp).
si PIN 1 'TSL1401R's SI pin.
clk PIN 2 'TSL1401R's CLK pin.
' -----[ Constants ]-------------------------------------------------------
DRK CON 0 'Value assignd to "which" for dark pixels.
BRT CON 1 'Value assigned to "which" for bright pixels.
FWD CON 0 'Value assigned to "dir" for left-to-right search.
BKWD CON 1 'Value assigned to "dir" for right-to-left search.
' -----[ Variables ]-------------------------------------------------------
VariableName VAR Byte ' What is variable for?
pdata VAR Word(8) 'Pixel data, as acquired LSB first from sensor.
pixels VAR pdata.BIT0 '128-bit pixel array mapped onto pdata.
exp VAR Word 'Exposure (integration) time in 2uSec units.
lptr VAR Byte 'Left pixel pointer for count and find operations.
rptr VAR Byte 'Right pixel pointer for count and find operations.
i VAR Byte 'General-purpose index.
cnt VAR Byte 'Result of pixel-count routine.
which VAR Bit 'Indicates seeking DRK or BRT pixels/edges.
dir VAR Bit 'Indicates direction of search (FWD or BKWD).
found VAR Bit 'Indicates pixels found (= 1), or not found (= 0).
' -----[ Program Code ]----------------------------------------------------
' NOTE: This code assumes that DEBUG will wrap after 128 characters,
' regardless of the DEBUG window width. Later versions of DEBUG
' may not do this, and you will have to add CRs where needed.
exp = 8333 'Set exposure time to 8333uSec (1/120th sec).
DEBUG HOME 'Go to home position on DEBUG screen.
GOSUB DispHdr 'Display the pixel location header.
DO 'Begin the scan-and-process loop.
GOSUB GetPix 'Obtain a pixel scan.
DEBUG CRSRXY, 0, 2 'Move to column 0, row 2.
GOSUB DispPix 'Display the pixels here.
lptr = 0 : rptr = 127: which = BRT : dir = FWD : found = 1
'Initialize parameters for find.
GOSUB FindEdge 'Find first dark-to-light edge going L->R.
dir = BKWD 'Switch directions.
GOSUB FindEdge 'Find first dark-to-light edge going L<-R.
DEBUG CLREOL 'Clear the next line.
IF found THEN 'Both edges found?
DEBUG CRSRX, (lptr - 1), "_|" 'Yes: Display left edge.
DEBUG CRSRX, rptr, "|_" ' Display right edge.
GOSUB CountPix ' Compute area (light pixel count).
DEBUG CR, CR, "Area = ", DEC cnt,' Display area ...
" Extent = ", DEC rptr - lptr + 1, CLREOL '... and extent of object.
ELSE 'No: Display failure message.
DEBUG CR, CR, "No object found.", CLREOL
ENDIF