
© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 11 of 52
' 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
'Still looking & within bounds?
IF (dir = FWD) THEN ' Yes: Search left-to-right?
FOR lptr = lptr TO rptr ' Yes: Loop forward.
IF (pixels(lptr) = which) THEN RETURN ' Return on match.
NEXT
ELSE
FOR rptr = rptr TO lptr ' No: Loop backward.
IF (pixels(rptr) = which) THEN RETURN ' Return on match.
NEXT
ENDIF
ENDIF
found = 0 'Didn't look or nothing found.
RETURN 'Return.
' -----[CountPix]----------------------------------------------------------
' Count pixels within the range lptr through rptr, of the type indicated by
' which (0 = dark; 1 = light).
CountPix:
cnt = 0 'Initialize count.
IF (lptr <= rptr AND rptr <= 127) THEN 'Valid range?
FOR i = lptr TO rptr ' Yes: Loop over desired range.
IF (pixels(i) = which) THEN cnt = cnt + 1 ' Add to count when pixel matches.
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:
2 = k × LightIntensity × IntegrationTime
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:
IntegrationTime = 2 / (k × LightIntensity)
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
inversely proportional
to that intensity level, and those
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: