Code: [Local Link Removed for Guests]
' Lilygo TTGO T-Display (135x240) ESP32 with PCM5102 I2S DAC
' Very important: Currently it only works well on Annex32 CAN 1.49.2
' Intercept errors
numError = 0
onError goto scared
' Retrieve the last tuned station or create a new file with the first one on the list
station = 1 : name$ = ""
if file.exists("/last.dat") then station = val(file.read$("/last.dat")) else file.save "/last.dat", str$(station)
for i =1 to station
READ name$, url$
next i
' Initialize display
tft.init 2 ' Orientation Portrait Reversed
tft.brightness 128 ' Brightness 0 to 255
background = tft.color(yellow)
' Create GUI objects
gui.init 4, background ' Background yellow
title$ = "Waiting data..." : vL = 0 : vR = 0
head = gui.textLine(45, 55, 230, 30, name$, 4, navy, background, background, 7)
body = gui.textLine(50, 90, 230, 30, title$, 3, black, background, background, 3)
vumL = gui.progressBar(45, 130, 230, 25, vL, 0, blue, white, black)
vumR = gui.progressBar(45, 157, 230, 25, vR, 0, red, white, black)
' Initialize I2S audio
volume = 75 : maxLevel = 0
play.setup 1, 64
play.volume volume
gosub playStation
onplay infoStation ' If streaming metadata is received
' Manage station change button
firstTime = 1
pin.mode 21, input, pullup
interrupt 21, changeStation
' Main loop
while 1
for i = 1 to 18 ' scrolls first 18 characters of title
gui.setText body, mid$(title$, 1, i)
gosub vumeter
next i
for i = 2 to len(title$) - 12 ' scrolls remaining title characters
gui.setText body, mid$(title$, i, 18)
gosub vumeter
next i
wend
END
'-----------
playStation:
'-----------
play.stream url$
if play.isplaying = 0 then
gui.setText head, "MISSING STATION"
title$ = "Station " + str$(station) + " not answer"
else
gui.setText head, name$
endif
gui.refresh
return
'-------
vumeter:
'-------
if play.vu_L > maxLevel then maxLevel = play.vu_L
if play.vu_R > maxLevel then maxLevel = play.vu_R
gui.setValue vumL, convert.map(play.vu_L, 0, maxLevel, 0, 100)
gui.setValue vumR, convert.map(play.vu_R, 0, maxLevel, 0, 100)
gui.refresh
pause 150
return
'------------
infoStation:
'------------
' Only activates when station changes song
info$ = play.message$
title$ = mid$(info$, instr(info$, "StreamTitle=") + 12)
if len(title$) = 1 then title$ = "No title information"
' Very special cases:
if name$ = "The 40's sounds" then replace$(title$, "Big Band Swing Jazz Jive 40s 50s", "")
' Other cases here..
blanks = 18 - (len(title$) MOD 18)
title$ = title$ + space$(blanks)
return
'--------------
changeStation:
'--------------
if pin(21) = 0 then return
if firstTime then
firstTime = 0
return
endif
pause 20 ' adjust for the best button debounce
if pin(21) = 1 then
READ name$, url$
station = station + 1
if numError = 33 then ' End of DATA
numError = 0 : station = 1
RESTORE
READ name$, url$
endif
file.save "/last.dat", str$(station)
maxLevel = 0
gosub playStation
endif
return
'-------
scared:
'-------
numError = BAS.ErrNum
return
' ===============================================================================
DATA "The Great American", "http://listen.shoutcast.com/thegreatamericansongbook"
DATA "Classica RAI", "http://icestreaming.rai.it/5.mp3"
DATA "Classical 90.5", "http://streaming.azpm.org:80/kuat192.mp3"
DATA "Radio Swiss Classic", "http://stream.srg-ssr.ch/m/rsc_de/mp3_128"
DATA "The 40's sounds", "http://81.17.57.158:24929/stream"
DATA "Vibe Radio Jazz", "http://94.130.242.5:8020/stream"
DATA "Rio de Janeiro", "http://26673.live.streamtheworld.com:80/NOVABRASIL_RIO_SC" ' broken link for test
DATA "Bosveld", "http://iceant.antfarm.co.za/Bosveld"
DATA "Jacaranda", "http://live.jacarandafm.com/jacarandahigh.mp3"
DATA "Latina", "http://start-latina.ice.infomaniak.ch/start-latina-high.mp3"
DATA "Rotterdam", "http://25333.live.streamtheworld.com:3690/VERONICA_SC"
DATA "Madrid", "http://server7.emitironline.com:8000/stream"