Download Print this page

Parallax TSL1401-DB Instructions Manual page 11

Linescan camera module

Advertisement

' Find the first pixel within the range lptr through rptr, in the direction
' given by dir and of the type indicated by which (0 = dark; 1 = light).
FindPix:
IF (found = 1 AND lptr <= rptr AND rptr <= 127) THEN
IF (dir = FWD) THEN
FOR lptr = lptr TO rptr
IF (pixels(lptr) = which) THEN RETURN '
NEXT
ELSE
FOR rptr = rptr TO lptr
IF (pixels(rptr) = which) THEN RETURN '
NEXT
ENDIF
ENDIF
found = 0
RETURN
' -----[CountPix]----------------------------------------------------------
' Count pixels within the range lptr through rptr, of the type indicated by
' which (0 = dark; 1 = light).
CountPix:
cnt = 0
IF (lptr <= rptr AND rptr <= 127) THEN
FOR i = lptr TO rptr
IF (pixels(i) = which) THEN cnt = cnt + 1 '
NEXT
ENDIF
RETURN
Pseudo-analog Pixel Acquisition
Even though pixels acquired by the BASIC Stamp are thresholded and converted to single bits, it's still
possible to obtain a picture of each pixel's analog value – at least for static subjects that don't move. The
voltage output from any given pixel in the TSL1401R can be expressed as follows:
Output voltage = k × LightIntensity × IntegrationTime
Where k is a constant. At the two-volt threshold level, this can be rewritten:
What we want this formula to answer is this: For a given light intensity to produce an output at the two-
volt threshold, how long does the integration time have to be? Solving the above equation gives us our
answer:
This means that if we want all the pixels whose light intensity is at or above a certain level to read as
ones, all we have to do is integrate for a time
pixels will read as ones after thresholding. By iterating over a range of intensity levels and displaying
each line of pixels one above the other, we can obtain an analog bar graph of intensity levels. Here's the
code snippet that does it. It can be plugged into the main code template shown above:
© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
2 = k × LightIntensity × IntegrationTime
IntegrationTime = 2 / (k × LightIntensity)
inversely proportional
'Still looking & within bounds?
'
Yes: Search left-to-right?
'
Yes: Loop forward.
Return on match.
'
No:
Loop backward.
Return on match.
'Didn't look or nothing found.
'Return.
'Initialize count.
'Valid range?
'
Yes: Loop over desired range.
Add to count when pixel matches.
to that intensity level, and those
Page 11 of 52

Advertisement

loading