I saw her message, I made a little program and I forgot to upload it!
Until Andy made me visit this page again today.
I understand that what he wants is a reduced version of the radio2.bas program.
I have started from the secondary file dial.bas to try to adapt it.
There it goes:
Code: [Local Link Removed for Guests]
' Lilygo TTGO T-Display ESP32 with PCM5102 I2S DAC
' and KY-040 rotary encoder to change stations.
' Tested with Annex32 CAN 1.48.22 (problems volume>50)
' Read text file with stations and fill
' arrays with name and streaming url address
file$ = "/stationR.txt"
index = word.count(file.read$(file$), "=") - 2
dim name$(index)
dim url$(index)
gosub loadArrays
' Retrieve the last tuned station or create
' a new file with the first one on the list
if file.exists("/last.dat") then
station = val(file.read$("/last.dat"))
else
station = 0
file.save "/last.dat", str$(station)
endif
' configure TFT screen
background = tft.color(yellow)
foreground = tft.color(black)
gosub TFT_init
' configure I2S DAC
gosub PLAY_init
' configure rotary encoder
turn = 0
CL = 13 ' clk pin to ESP32 GPIO13
DT = 12 ' dt pin to ESP32 GPIO12
pin.mode CL, input, pullup ' enable internal pull-up resistors
pin.mode DT, input, pullup
interrupt CL, readCL
gosub menu
goto bucle
wait
bucle:
while 1
if turn = 1 then
pause 15 ' debounce
if pin(CL) = 1 then
do
loop until pin(DT) = 0
num = pin(CL) << 2
num = num OR pin(DT)
if num = 0 then station = station + 1 ' clockwise
if station > index then station = index ' upper limit
if num = 4 then station = station - 1 ' counterclockwise
if station < 0 then station = 0 ' lower limit
play.stream url$(station), 40000
pause 50
' wlog station, name$(station)
gosub menu
file.save "/last.dat", str$(station)
endif
turn = 0
endif
wend
return
END
' --------------------------------------
menu:
select case station
case 0
emisora = 0
row = 0
case index-3 to index
emisora = index-3
row = 3 - (index mod station)
case else
emisora = station-1
row = 1
end select
tft.fill background
for y = 62 to 152 step 30
tft.text.draw name$(emisora), 50, y
emisora = emisora + 1
next y
tft.text.color white, blue
tft.text.draw name$(station), 50, (row*30) + 62
tft.text.color foreground, background
return
' ---------------------------
readCL:
if pin(CL) = 0 then return
if turn = 1 then return
turn = 1 ' If you've made it this far, you've earned it.
return
' --------------------------------------
loadArrays:
for i = 0 to index
line$ = file.read$(file$, i+1)
name$(i) = word$(line$, 1, "=")
url$(i) = replace$(word$(line$, 2, "="), chr$(13), "") ' remove cr from end of line
next i
return
' --------------------------------------
TFT_init:
tft.init 2 ' orientation Portrait Reversed
tft.brightness 128 ' brightness = 0 to 255
tft.text.color foreground, background
tft.text.align 0
tft.fill background
tft.text.font 4
return
' --------------------------------------
PLAY_init:
play.setup 1, 64 ' output to external DAC, buffer=64, stereo
play.volume 50
play.stream url$(station), 40000
return
' --------------------------------------
'info1:
' tft.text.font 3
' tft.text.draw bas.ver$, 55, 65
' tft.text.draw "Version " + str$(bas.ver), 55, 95
' tft.text.draw bas.ssid$, 55, 125
' tft.text.draw "IP " + word$(ip$, 1), 55, 155
' pause 5000
'return
' ********** HARDWARE **********
' PCM5102 ESP32
' ------- -------
' BCK GPIO27
' DIN GPIO02
' LCK GPIO26
' GND GND
' VIN +5V
' SCK GND (to avoid oscillations)
' rotary encoder KY-040
' It does not use either the resistors on the board or the connection to Vcc.
' ESSENTIAL two 100nF capacitors between CLK/DT and GND
' KY-040 ESP32
' ------ ------
' CLK GPIO13
' DT GPIO12
' SW N/C
' + N/C
' GND GND
[Local Link Removed for Guests]