Download Quakes32-S.zip if using ILI9341 (240x320) display.
Download Quakes32-L.zip if using ILI9487 or ILI9488 (320x480) display.
You will need Annex32 V1.43.5 or higher for ILI9488.
The zip file contains the program file and the map JPG to go with it.
I'm listing just the larger screen version here for neatness.
This won a runners-up prize in the recent Instructables Maps Challenge
Full build details are HERE.
Code: [Local Link Removed for Guests]
'
' Quakes32 V1.1 for ESP32 and ILI9487/9488 (320x480)
' Uses map image map-l.jpg.
' AndyGadget 2021
'
' Tidied up code, added overnight dimming of display
' added more comments and improved event location dot accuracy.
'
wlog can.stop ' Kill CanBus as not required
OPTION.NTPSYNC ' Sync to internet time (Mage sure Timezone is correct on Config screen
TFT.INIT 1 ' May need TFT.INIT 3, depending on screen orientation.
TFT.BRIGHTNESS 255
' Various variable definitions.
FName$ = "/history.txt"
OldRef$ = ""
dim Hist(100,3)
PLat = 0 : PLon = 0 : PMag = 0
EOL$ = chr$(10)
tft.text.align 4
tft.text.col Yellow
tft.text.font 4
' Display bare map on screen.
tft.jpg "/map-l.jpg"
if file.exists(FName$) = 1 then
' Read event history from file into array.
for FCnt = 1 to 100
FLine$ = file.read$(FName$,FCnt)
Hist(FCnt,0) = val(word$(FLine$,1,"|"))
Hist(FCnt,1) = val(word$(FLine$,2,"|"))
Hist(FCnt,2) = val(word$(FLine$,3,"|"))
next FCnt
end if
'Sets routine to call when data received from seismic portal API.
ONWGETASYNC MsgReceived
gosub QueryServer
' Set timer to run Blink routine every 500mS
timer0 500, Blink
' Set timer to run data request routine every 30 seconds.
timer1 30000, QueryServer
' Do nothing and wait for the events above to occur.
wait
' SUBROUTINES
' ***********
QueryServer:
' Request data from SeismicPortal API - No key needed.
' JSON is an option but chose simple delimited text string output.
' Requesting only most recent event.
' Green dot in top centre of screen - Clears when data received.
TFT.CIRCLE 224, 10, 3,green,1
wgetasync("seismicportal.eu/fdsnws/event/1/query?limit=1&format=text",443,0,1)
' Turn TFT brightness down overnight
Hour = val(left$(time$,2))
if (Hour >=23) or (Hour <=7) then TFT.BRIGHTNESS 20 else TFT.BRIGHTNESS 255
return
MsgReceived:
' Seismic portal API has replied ot data request.
TFT.CIRCLE 224, 10, 3,&H3475,1
Line$ = WORD$( WGETRESULT$, 2, chr$(10))
Ref$ = word$(Line$,1,"|")
' Only process result if it is a new event.
if (Ref$ <> OldRef$) and (val(Ref$) <> 0) then
wlog line$
OldRef$ = Ref$
' Extract the data items we want from returned data line.
TD$ = word$(Line$,2,"|")
EDate$ = left$(TD$,10)
ETime$ = left$(time$,5)
EMag$ = word$(Line$,11,"|")
ELoc$ = word$(Line$,13,"|")
Lat = val(word$(Line$,3,"|"))
Lon = val(word$(Line$,4,"|"))
' Load map to clear display, then print text info about event.
TFT.JPG "/map-l.jpg"
tft.text.draw EMag$,40,30
tft.text.draw ETime$,420,30
tft.text.draw ELoc$, 240,300
' Shift array.
For Cnt = 0 to 99
Hist(Cnt,0) = Hist(Cnt+1,0)
Hist(Cnt,1) = Hist(Cnt+1,1)
Hist(Cnt,2) = Hist(Cnt+1,2)
next Cnt
' Convert longitude and latitude of event to screen co-ordinates.
' Size of plotted circle is proportional to quake magnitude.
PLon = (225 + (1.334 * Lon)) mod 480
PLat = 225 - 1.333*(((0.86 * Lat) + (Lat * 0.0475)^3))
PMag = cint(val(EMag$) * 1.0)
if PMag <= 1 then PMag = 1
' Write new event to array.
Hist(100,0) = PLon
Hist(100,1) = PLat
Hist(100,2) = PMag
' Plot event history from array.
for HCnt = 0 to 100
RedVal = 155 + HCnt
GrnVal = 55 + (HCnt * 2)
BluVal = 0
' Colour of plotted point fades from bright yellow through orange to dull red with age.
TFT.CIRCLE Hist(HCnt,0),Hist(HCnt,1),Hist(HCnt,2),TFT.RGB(RedVal,GrnVal,BluVal),1
next HCnt
' Plot most recent event.
TFT.CIRCLE PLon,Plat,PMag,&HF800,1
' Store array to file.
' DO NOT STOP PROGRAM WHEN RED DOT AT TOP OF SCREEN
' OTHERWISE HISTORY FILE WILL BE CORRUPTED.
TFT.CIRCLE 224, 10, 3,red,1
x = file.delete(FName$)
for FCnt = 1 to 100
FLine$ = str$(Hist(FCnt,0)) + "|" + str$(Hist(FCnt,1)) + "|" + str$(Hist(FCnt,2)) + EOL$
file.append FName$,FLine$
next FCnt
TFT.CIRCLE 224, 10, 3,&H3475,1
endif
return
Blink:
' Flashing red / yellow dot to mark most recent event.
Flsh = (Flsh + 1) mod 2
if Flsh = 0 then
TFT.CIRCLE PLon,PLat,PMag,Yellow,1
else
TFT.CIRCLE PLon,PLat,PMag,Red,1
endif
return