Hello all,
I am working on a project for my dad that finds the speed of a small model train (N Scale or 1:144), scales the speed, finds what the speed would be in real life and displays it on a 3 digit 7 segmented LED display.
I have created two scripts provided below: one that works normally, and one that rounds the speed before displaying it.
My problem is that the script says that the hunds, tens and ones variable all hold a value bigger than 40.
I don't understand how this works and i don't think that the program is working correctly.
It correctly calculates the scaled speed, but there is a problem with the BinToASCII command.
The hunds, tens and ones variables should hold numbers in between 0 and 9.
It seems that calculating those variables are the hardest part of this project (Unbelievably).
Please could anyone tell me where I have gone wrong.
Thanking any help,
Technokid
P.S Sorry. I don't put remarks in my scripts due to many complications finding the right symbol.
Rounded Code:
Normal Code:
I am working on a project for my dad that finds the speed of a small model train (N Scale or 1:144), scales the speed, finds what the speed would be in real life and displays it on a 3 digit 7 segmented LED display.
I have created two scripts provided below: one that works normally, and one that rounds the speed before displaying it.
My problem is that the script says that the hunds, tens and ones variable all hold a value bigger than 40.
I don't understand how this works and i don't think that the program is working correctly.
It correctly calculates the scaled speed, but there is a problem with the BinToASCII command.
The hunds, tens and ones variables should hold numbers in between 0 and 9.
It seems that calculating those variables are the hardest part of this project (Unbelievably).
Please could anyone tell me where I have gone wrong.
Thanking any help,
Technokid
P.S Sorry. I don't put remarks in my scripts due to many complications finding the right symbol.
Rounded Code:
Code:
symbol hund = b0
symbol tens = b1
symbol ones = b2
symbol speed = b3
dirsc = %01111111
Start:
b4 = 0
b7 = 0
hund = 0
tens = 0
ones = 0
speed = 0
goto MainsA
MainsA:
readadc b.3,b3
if b3 < 75 then goto MainsA
goto SignalFound
SignalFound:
pause 100
b4 = b4 + 1
readadc b.4,b5
if b5 < 75 then goto SignalFound
b4 = b4 / 10
speed = 30/b4
speed = speed * 144
if speed > 999 then goto Verify
bintoascii speed,hund,tens,ones
goto MainsB
MainsB:
high b.5
if hund = 0 then let pinsc = %01111110
endif
if hund = 1 then let pinsc = %00110000
endif
if hund = 2 then let pinsc = %01101101
endif
if hund = 3 then let pinsc = %01111001
endif
if hund = 4 then let pinsc = %00110011
endif
if hund = 5 then let pinsc = %01011101
endif
if hund = 6 then let pinsc = %01011111
endif
if hund = 7 then let pinsc = %01110000
endif
if hund = 8 then let pinsc = %01111111
endif
if hund = 9 then let pinsc = %01111011
endif
pause 15
let pinsc = %00000000
low b.5
high b.6
if tens = 0 then let pinsc = %01111110
endif
if tens = 1 then let pinsc = %00110000
endif
if tens = 2 then let pinsc = %01101101
endif
if tens = 3 then let pinsc = %01111001
endif
if tens = 4 then let pinsc = %00110011
endif
if tens = 5 then let pinsc = %01011101
endif
if tens = 6 then let pinsc = %01011111
endif
if tens = 7 then let pinsc = %01110000
endif
if tens = 8 then let pinsc = %01111111
endif
if tens = 9 then let pinsc = %01111011
endif
pause 15
let pinsc = %00000000
low b.6
high b.7
if ones = 0 then let pinsc = %01111110
endif
if ones = 1 then let pinsc = %00110000
endif
if ones = 2 then let pinsc = %01101101
endif
if ones = 3 then let pinsc = %01111001
endif
if ones = 4 then let pinsc = %00110011
endif
if ones = 5 then let pinsc = %01011101
endif
if ones = 6 then let pinsc = %01011111
endif
if ones = 7 then let pinsc = %01110000
endif
if ones = 8 then let pinsc = %01111111
endif
if ones = 9 then let pinsc = %01111011
endif
pause 20
let pinsc = %00000000
low b.7
b7 = b7 + 1
if b7 < 60 then goto MainsB
goto Start
Verify:
speed = speed + 1 / 2
bintoascii speed,hund,tens,ones
goto MainsB
Code:
symbol hund = b0
symbol tens = b1
symbol ones = b2
symbol speed = b3
dirsc = %01111111
Start:
b4 = 0
b7 = 0
hund = 0
tens = 0
ones = 0
speed = 0
goto MainsA
MainsA:
readadc b.3,b3
if b3 < 75 then goto MainsA
goto SignalFound
SignalFound:
pause 100
b4 = b4 + 1
readadc b.4,b5
if b5 < 75 then goto SignalFound
b4 = b4 / 10
speed = 30/b4
speed = speed * 144
bintoascii speed,hund,tens,ones
goto MainsB
MainsB:
high b.5
if hund = 0 then let pinsc = %01111110
endif
if hund = 1 then let pinsc = %00110000
endif
if hund = 2 then let pinsc = %01101101
endif
if hund = 3 then let pinsc = %01111001
endif
if hund = 4 then let pinsc = %00110011
endif
if hund = 5 then let pinsc = %01011101
endif
if hund = 6 then let pinsc = %01011111
endif
if hund = 7 then let pinsc = %01110000
endif
if hund = 8 then let pinsc = %01111111
endif
if hund = 9 then let pinsc = %01111011
endif
pause 15
let pinsc = %00000000
low b.5
high b.6
if tens = 0 then let pinsc = %01111110
endif
if tens = 1 then let pinsc = %00110000
endif
if tens = 2 then let pinsc = %01101101
endif
if tens = 3 then let pinsc = %01111001
endif
if tens = 4 then let pinsc = %00110011
endif
if tens = 5 then let pinsc = %01011101
endif
if tens = 6 then let pinsc = %01011111
endif
if tens = 7 then let pinsc = %01110000
endif
if tens = 8 then let pinsc = %01111111
endif
if tens = 9 then let pinsc = %01111011
endif
pause 15
let pinsc = %00000000
low b.6
high b.7
if ones = 0 then let pinsc = %01111110
endif
if ones = 1 then let pinsc = %00110000
endif
if ones = 2 then let pinsc = %01101101
endif
if ones = 3 then let pinsc = %01111001
endif
if ones = 4 then let pinsc = %00110011
endif
if ones = 5 then let pinsc = %01011101
endif
if ones = 6 then let pinsc = %01011111
endif
if ones = 7 then let pinsc = %01110000
endif
if ones = 8 then let pinsc = %01111111
endif
if ones = 9 then let pinsc = %01111011
endif
pause 20
let pinsc = %00000000
low b.7
b7 = b7 + 1
if b7 < 60 then goto MainsB
goto Start
Last edited: