GPS (From SB Example File)

Post Reply
User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

GPS (From SB Example File)

Post by GeorgeMcGinn »

Here is the code GPS.TXT" from EXAMPLES with a minor modification.

At the end of the fields I added a new one that shows one of 16 compass points that is easy to understand (N, S, NNE, etc).

The new code is colored RED and is to show how to update this program. For those who are new to SmartBASIC, this example shows how you can udpdate GPS fields in real time. The additions are also updated in real time.

This can be added to the EXAMPLES if desired.

Code: Select all

OPTION BASE 1
OPTION SCREENLOCK OFF
' turn on GPS
SET GPS ON

'r' 'Load Compass Positions
DIM DIR$(17)
FOR I = 1 TO 17
    READ DIR$(I)
NEXT I
''
' prepare UI
GRAPHICS
DRAW FONT NAME "Optima-Regular"
DRAW FONT SIZE 25
DRAW COLOR .7,1,1
DRAW TEXT "Latitude:" AT 15,20
FIELD "lat" TEXT "N/A" AT 150,20 SIZE 130,30
DRAW TEXT "°" AT 290,20
DRAW TEXT "Longitude:" AT 15,60
FIELD "lon" TEXT "N/A" AT 150,60 SIZE 130,30
DRAW TEXT "°" AT 290,60
DRAW TEXT "Altitude:" AT 15,100
FIELD "alt" TEXT "N/A" AT 150,100 SIZE 80,30
DRAW TEXT "m" AT 240,100
DRAW TEXT "Heading:" AT 15,140
FIELD "head" TEXT "N/A" AT 150,140 SIZE 90,30
DRAW TEXT "°" AT 250,140
DRAW TEXT "Course:" AT 15,180
FIELD "course" TEXT "N/A" AT 150,180 SIZE 80,30
DRAW TEXT "°" AT 240,180
DRAW TEXT "Speed:" AT 15,220
FIELD "speed" TEXT "N/A" AT 150,220 SIZE 80,30
DRAW TEXT "km/h" AT 240,220
'r'!DRAW TEXT "Compass:" AT 15,260
FIELD "compass$" TEXT "N/A" AT 150,260 SIZE 80,30
''
x=-1!y=-1!z=-1!s=-1!c=-1
LOOP:
' get GPS data
IF GPS_COUNT() THEN GET GPS LAT x LON y ALT z SPD s CRS c HAC h VAC v
ch=COMPASS_HEADING()
ca=COMPASS_ACCURACY()
' output GPS data
IF x <> -1 AND h <> -1 THEN FIELD "lat" SET TEXT STR$(x,"#.#######")
IF y <> -1 AND h <> -1 THEN FIELD "lon" SET TEXT STR$(y,"#.#######")
IF z <> -1 AND v <> -1 THEN FIELD "alt" SET TEXT STR$(z,"#.#")
IF ch <> -1 AND ca <> -1 THEN FIELD "head" SET TEXT STR$(ch,"#")&" ± "&STR$(ca,"#")
IF s <> -1 THEN FIELD "speed" SET TEXT STR$(s*3.6,"#.#")
IF c <> -1 THEN FIELD "course" SET TEXT STR$(c,"#.#")
'r'!IF ch <> -1 THEN i=ABS(ch/22.5)+1!compass$=DIR$(i)!FIELD "compass$" SET TEXT compass$
''
GOTO LOOP

'r'points:
DATA "N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"
''
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: GPS (From SB Example File)

Post by rbytes »

This is a useful addition. Thanks, George.
The only thing that gets me down is gravity...

Post Reply