setfreq m8
write 19,"1"
'blank stored numbers
for b0 = 0 to 17
write b0,"0"
next b0
main:
'Wait till receive barcode from barcode scanner
serin 1,N4800,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
'goto ticket_ok
'check for four fixed digits to know its my codebar
'ticket_ok:
if b8="3" and b9 = "7" and b10 = "0" and b11 = "0" then goto check1
'goto check1 'if its my codebar then go check
'else
'goto main
'end if
goto main
'This routines compares the received number with the last 3 saved numbers, if its different then it opens door
check1:
for b0 = 0 to 5
read b0, b13
lookdown b0,(b1,b2,b3,b4,b5,b6),b7
if b13 <> b7 then goto check2
next b0
'read 1, b13
'if b13 <> b1 then goto check2
'read 2, b13
'if b13 <> b2 then goto check2
'read 3, b13
'if b13 <> b3 then goto check2
'read 4, b13
'if b13 <> b4 then goto check2
'read 5, b13
'if b13 <> b5 then goto check2
'read 6, b13
'if b13 <> b6 then goto check2
goto main
check2:
for b0 = 6 to 11
read b0, b13
lookdown b0,(0,0,0,0,0,0,b1,b2,b3,b4,b5,b6),b7
if b13 <> b7 then goto check3
next b0
'read 7, b13
'if b13 <> b1 then goto check3
'read 8, b13
'if b13 <> b2 then goto check3
'read 9, b13
'if b13 <> b3 then goto check3
'read 10, b13
'if b13 <> b4 then goto check3
'read 11, b13
'if b13 <> b5 then goto check3
'read 12, b13
'if b13 <> b6 then goto check3
goto main
check3:
for b0 = 12 to 17
read b0, b13
lookdown b0,(0,0,0,0,0,0,0,0,0,0,0,0,b1,b2,b3,b4,b5,b6),b7
if b13 <> b7 then goto open
next b0
'read 13, b13
'if b13 <> b1 then goto open
'read 14, b13
'if b13 <> b2 then goto open
'read 15, b13
'if b13 <> b3 then goto open
'read 16, b13
'if b13 <> b4 then goto open
'read 17, b13
'if b13 <> b5 then goto open
'read 18, b13
'if b13 <> b6 then goto open
goto main
'flahs led and open door
open:
high 4
high 5
pause 4000
low 4
low 5
'gosub save
'if the number was succesfull then save it
'save:
read 19,b13
select case b13
case "1"
b0 = 6
write 19,"2"
case "2"
b0 = 12
write 19,"3"
case "3"
b0 = 0
write 19,"1"
end select
for b7 = 0 to 5
lookdown b7,(b1,b2,b3,b4,b5,b6),b8
write b0,b8
inc b0
next b7
'write b0,b1
'gosub sum_b0
'write b0,b2
'gosub sum_b0
'write b0,b3
'gosub sum_b0
'write b0,b4
'gosub sum_b0
'write b0,b5
'gosub sum_b0
'write b0,b6
goto main
'sum_b0:
'b0 = b0 +1
'return