© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 43 of 52
Here is the program that sorts this all out and gives a pass/fail grade to each bottle it sees:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
liq_btm VAR Byte
liq_top VAR Byte
cap_btm VAR Byte
cap_top VAR Byte
liq_lvl VAR Byte
cap_siz VAR Byte
i VAR Byte
pix VAR Byte
OWOUT owio, 1, [SETEXP, 60]
OWOUT owio, 0, [SETBIN, 0, 1, FLOAT|LEVEL|5]
DO
SERIN 16, 84, [WAIT(" ")]
OWOUT owio, 0, ["<", ACQBIN, FNDNXT|FWD|DRKEDG]
OWOUT owio, 0, [FNDNXT|FWD|BRTEDG, FNDNXT|BKWD|DRKEDG]
OWOUT owio, 0, [FNDNXT|BKWD|BRTEDG, ">"]
GOSUB Ready
OWOUT owio, 0, [DUMPADR, PIXELS]
DEBUG CLS
FOR i = 0 TO 31
OWIN owio, 0, [pix]
DEBUG BIN8 pix REV 8
IF (i & 7 = 7) THEN DEBUG CR
NEXT
OWOUT owio, 1, [DUMPADR, R 5]
OWIN owio, 2, [liq_btm, liq_top, cap_top, cap_btm]
cap_siz = cap_top - cap_btm
liq_lvl = l liq_btm >> 1
IF (cap_siz > 35 AND cap_top < 206 AND liq_lvl > 110 AND liq_lvl < 130) THEN
DEBUG CR, "Pass"
ELSE
DEBUG CR, "Fail"
ENDIF
DEBUG ": Cap Size = ", DEC cap_siz, " Cap Top = ", DEC cap_top
DEBUG " Liquid Level = ", DEC liq_lvl
LOOP
Unlike the prior program, which relies on a falling edge on
P3
to trigger a new scan, this one operates
more in demo mode, in that the trigger comes from tapping the spacebar in the DEBUG window. Here’s a
blow-by-blow description: