grkblood13
04-18-2007, 01:13 AM
what i attempting to do is take a value from a scale and put it into 1 of three buckets. the bucket that the number will go into is the bucket with the lowest present number.
' {$STAMP BS2}
' {$PBASIC 2.5}
max_seats VAR Word 'test run value
sect_pass VAR Byte
sect_pass1 VAR Byte
sect_pass2 VAR Byte
sect_pass3 VAR Byte
total_weight VAR Word
keycount VAR Nib
man VAR Nib
Aircraft_Ident VAR Word
Aircraft_pass VAR Word
Current_weight VAR Word
Aircraft_weight VAR Word
Yes_No VAR Bit
aircraft_weight = 2000
sect_pass = 2000/3
total1 VAR Word
total2 VAR Word
total3 VAR Word
begin:
HIGH 9
HIGH 10
IF IN9 = 0 AND IN10 = 1 THEN calc 'tells program to weigh'
IF IN9 = 1 AND IN10 = 0 THEN standby 'someone is walking through scale backwards'
IF IN9 = 1 AND IN10 = 1 THEN begin 'loops tripwire'
standby:
DO
IF IN9 = 1 OR IN10 = 1 THEN begin 'this is just to make sure there are no glitches'
LOOP
calc:
location CON 0
i VAR Nib
total VAR Word
'Aircraft_Ident = 0
'Aircraft_Ident = (INS & $01FF)
PAUSE 1000 'delay to compensate for time to get on scale'
total = 0
FOR i = 1 TO 15
total = total + (INS & $01FF)' - Aircraft_Ident 'takes reading from IN0 - IN8'
PAUSE 100 'this delay is because the converter is running at 10 Hz'
NEXT
total = total / 15
WRITE location,total
PAUSE 500
'DEBUG DEC total
second:
HIGH 9
HIGH 10
DO
IF IN9 = 1 AND IN10 = 0 THEN add 'adds weight to bins'
IF IN9 = 0 AND IN10 = 1 THEN begin 'starts over because someone stepped off scale'
IF IN9 = 1 AND IN10 =1 THEN second
IF IN9 = 0 AND IN10 =0 THEN second
LOOP
END
RETURN
add:
pit1 CON 0
pit2 CON 0
pit3 CON 0
total_weight = 0
DEBUG CR, DEC total1
DEBUG CR, DEC total2
DEBUG CR, DEC total3
IF (total1 < total2) AND (total1 < total3) THEN add1 'add weight to pit1'
IF (total2 < total1) AND (total2 < total3) THEN add2 'add weight to pit2'
IF (total3 < total1) AND (total3 < total2) THEN add3 'add weight to pit3'
IF (total1 = total2 = total3) THEN add2 'they equal so add to pit2'
IF (total1 = total2) THEN add2 '(1&2 is less than 3)'
IF (total1 = total3) THEN add1 '(1&3 is less than 2)'
IF (total2 = total3) THEN add3 '(2&3 is less than 1)'
add1:
IF sect_pass1 > sect_pass THEN check1
total1 = total1 + total
total_weight = total_weight + total1 'totals weight
'SEROUT 11,84, [$0C, "section 1 =", DEC total1]
DEBUG CR, "section 1 ="
PAUSE 1500
DEBUG DEC total1
WRITE pit1,total1
DEBUG CR
sect_pass1 = sect_pass1 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
add2:
IF sect_pass2 > sect_pass THEN check2
total2 = total2 + total
total_weight = total_weight + total2 'totals weight
'SEROUT 11,84, [$0C, "section 2 =", DEC total2]
DEBUG CR, "section 2 ="
PAUSE 1500
DEBUG DEC total2
WRITE pit2,total2
DEBUG CR
sect_pass2 = sect_pass2 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
add3:
IF sect_pass3 > sect_pass THEN check3
total3 = total3 + total
total_weight = total_weight + total3 'totals weight
'SEROUT 11,84, [$0C, "section 3 =", DEC total3]
DEBUG CR, "section 3 ="
PAUSE 1500
DEBUG DEC total3
WRITE pit3,total3
DEBUG CR
sect_pass3 = sect_pass3 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
check1:
'SEROUT 11,84, [$0C, "section 1 full"]
DEBUG CR
DEBUG CR, "section 1 full",CR
IF sect_pass2 < sect_pass3 THEN add2
IF sect_pass2 > sect_pass3 THEN add3
IF sect_pass2 = sect_pass3 THEN add2
check2:
'SEROUT 11,84, [$0C, "section 2 full"]
DEBUG CR
DEBUG CR, "section 2 full",CR
IF sect_pass1 < sect_pass3 THEN add1
IF sect_pass1 > sect_pass3 THEN add3
IF sect_pass1 = sect_pass3 THEN add1
check3:
'SEROUT 11,84, [$0C, "section 3 full"]
DEBUG CR
DEBUG CR, "section 3 full",CR
IF sect_pass1 < sect_pass2 THEN add1
IF sect_pass1 > sect_pass2 THEN add2
IF sect_pass1 = sect_pass2 THEN add1
full: 'stops program when plane is full
SEROUT 11,84, [$0C, "plane has reached weight limit"]
DEBUG CR
DEBUG CR, "plane has reached weight limit"
END
all that it does is constantly add to bucket 2. i did assign numbers into the variable as a test run with total1=2 and total2= 4. when i did that it added to total3. does anybody know the problem?
Post Edited (grkblood13) : 4/17/2007 6:19:30 PM GMT
' {$STAMP BS2}
' {$PBASIC 2.5}
max_seats VAR Word 'test run value
sect_pass VAR Byte
sect_pass1 VAR Byte
sect_pass2 VAR Byte
sect_pass3 VAR Byte
total_weight VAR Word
keycount VAR Nib
man VAR Nib
Aircraft_Ident VAR Word
Aircraft_pass VAR Word
Current_weight VAR Word
Aircraft_weight VAR Word
Yes_No VAR Bit
aircraft_weight = 2000
sect_pass = 2000/3
total1 VAR Word
total2 VAR Word
total3 VAR Word
begin:
HIGH 9
HIGH 10
IF IN9 = 0 AND IN10 = 1 THEN calc 'tells program to weigh'
IF IN9 = 1 AND IN10 = 0 THEN standby 'someone is walking through scale backwards'
IF IN9 = 1 AND IN10 = 1 THEN begin 'loops tripwire'
standby:
DO
IF IN9 = 1 OR IN10 = 1 THEN begin 'this is just to make sure there are no glitches'
LOOP
calc:
location CON 0
i VAR Nib
total VAR Word
'Aircraft_Ident = 0
'Aircraft_Ident = (INS & $01FF)
PAUSE 1000 'delay to compensate for time to get on scale'
total = 0
FOR i = 1 TO 15
total = total + (INS & $01FF)' - Aircraft_Ident 'takes reading from IN0 - IN8'
PAUSE 100 'this delay is because the converter is running at 10 Hz'
NEXT
total = total / 15
WRITE location,total
PAUSE 500
'DEBUG DEC total
second:
HIGH 9
HIGH 10
DO
IF IN9 = 1 AND IN10 = 0 THEN add 'adds weight to bins'
IF IN9 = 0 AND IN10 = 1 THEN begin 'starts over because someone stepped off scale'
IF IN9 = 1 AND IN10 =1 THEN second
IF IN9 = 0 AND IN10 =0 THEN second
LOOP
END
RETURN
add:
pit1 CON 0
pit2 CON 0
pit3 CON 0
total_weight = 0
DEBUG CR, DEC total1
DEBUG CR, DEC total2
DEBUG CR, DEC total3
IF (total1 < total2) AND (total1 < total3) THEN add1 'add weight to pit1'
IF (total2 < total1) AND (total2 < total3) THEN add2 'add weight to pit2'
IF (total3 < total1) AND (total3 < total2) THEN add3 'add weight to pit3'
IF (total1 = total2 = total3) THEN add2 'they equal so add to pit2'
IF (total1 = total2) THEN add2 '(1&2 is less than 3)'
IF (total1 = total3) THEN add1 '(1&3 is less than 2)'
IF (total2 = total3) THEN add3 '(2&3 is less than 1)'
add1:
IF sect_pass1 > sect_pass THEN check1
total1 = total1 + total
total_weight = total_weight + total1 'totals weight
'SEROUT 11,84, [$0C, "section 1 =", DEC total1]
DEBUG CR, "section 1 ="
PAUSE 1500
DEBUG DEC total1
WRITE pit1,total1
DEBUG CR
sect_pass1 = sect_pass1 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
add2:
IF sect_pass2 > sect_pass THEN check2
total2 = total2 + total
total_weight = total_weight + total2 'totals weight
'SEROUT 11,84, [$0C, "section 2 =", DEC total2]
DEBUG CR, "section 2 ="
PAUSE 1500
DEBUG DEC total2
WRITE pit2,total2
DEBUG CR
sect_pass2 = sect_pass2 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
add3:
IF sect_pass3 > sect_pass THEN check3
total3 = total3 + total
total_weight = total_weight + total3 'totals weight
'SEROUT 11,84, [$0C, "section 3 =", DEC total3]
DEBUG CR, "section 3 ="
PAUSE 1500
DEBUG DEC total3
WRITE pit3,total3
DEBUG CR
sect_pass3 = sect_pass3 + 1 'increments seat counter
IF total_weight = aircraft_weight THEN full 'plane has reached max weight
IF total_weight > aircraft_weight THEN full
GOSUB begin
check1:
'SEROUT 11,84, [$0C, "section 1 full"]
DEBUG CR
DEBUG CR, "section 1 full",CR
IF sect_pass2 < sect_pass3 THEN add2
IF sect_pass2 > sect_pass3 THEN add3
IF sect_pass2 = sect_pass3 THEN add2
check2:
'SEROUT 11,84, [$0C, "section 2 full"]
DEBUG CR
DEBUG CR, "section 2 full",CR
IF sect_pass1 < sect_pass3 THEN add1
IF sect_pass1 > sect_pass3 THEN add3
IF sect_pass1 = sect_pass3 THEN add1
check3:
'SEROUT 11,84, [$0C, "section 3 full"]
DEBUG CR
DEBUG CR, "section 3 full",CR
IF sect_pass1 < sect_pass2 THEN add1
IF sect_pass1 > sect_pass2 THEN add2
IF sect_pass1 = sect_pass2 THEN add1
full: 'stops program when plane is full
SEROUT 11,84, [$0C, "plane has reached weight limit"]
DEBUG CR
DEBUG CR, "plane has reached weight limit"
END
all that it does is constantly add to bucket 2. i did assign numbers into the variable as a test run with total1=2 and total2= 4. when i did that it added to total3. does anybody know the problem?
Post Edited (grkblood13) : 4/17/2007 6:19:30 PM GMT