These days i tried to use the $GPVTG sentence and get the speed from there as it is in Km/h
First of all the format of the $GPVTG sentence is as follows.
1. X.XX for the left X before the "dot" when the speed is less than 10km/h
2. XX.XX for the XX before the "dot" when the speed is more than 9 km/h and less than 100km/h
2. XXX.XX for the XXX before the "dot" when the speed is more than 99km/h
For the .XX so the two digits after the "dots" those are the decimal part and stays stable in the $GPVTG sentence.
We need to check when the speed change, where is the dot.
Code:
serin2 gps_tx,84,timeout,lostcable,[wait("GPVTG"),wait("N"),_
wait(","),TS[0],TS[1],TS[2],TS[3],TS[4],_
wait(","),SKIP 3]
for i = 1 to 3
if TS[i]="." then decimal = i 'TOTAL SPEED. find which character is the decimal point
next i
select case decimal 'if the gps shows 1.45 it may be 145
'for the conversion ASCII to number we can use the -48
case 1 'decimal position is x.xx
speed = (10*(TS[0]-48))+(TS[2]-48)
case 2 'decimal position is xx.xx
speed = (100*(TS[0]-48))+(10*(TS[1]-48))+(TS[3]-48)
case 3 'decimal position is xxx.xx
speed = (1000*(TS[0]-48))+(100*(TS[1]-48))+(10*(TS[2]-48))
end select
gosub OVERSPEED:
OVERSPEED:
if SPEED > 1000 then ' 100Km/h
high porta.3
low porta.2
low porta.1
else
LOW porta.3
if SPEED > 500 then ' 50Km/h
high porta.2
low porta.1
else
LOW porta.2
if SPEED > 100 then ' 10Km/h
high porta.1
else
LOW porta.1
endif
endif
endif
return
At the moment the code is working as it is, but i think i need to change the multiplication of 10*, 100* and 1000*, to 1*, 10* and 100*, because as you see at the OVERSPEED: i use 1000 for the 100 km/h, 500 for the 50km/h and 100 for the 10km/h.
But then the dot will change place, or i will not being able to identify the right place of it. Anyhow the code is working for the speed.
Still i need to:
1. Make the Day/Month/Year to work properly, now i think i will not have a problem to solve this.
2. The display data are refreshed, my goal is to make the data stable all the time at the screen and change only the needed values.
Bookmarks