'FULL TFT FM RADIO: memclear ' Launch Radio RADIOon 104.2 delay 100 FREQ 104.2 rdstype1 = "News,Current Affairs,Information,Sport,Education,Drama,Culture,Science,Varied,Pop,Rock,Easy Listening,Light Classics,Serious Classics,Other music,Weather" rdstype2 = "Finance,Children,Social Affairs,Religion,Phone In,Travel,Leisure,Jazz,Country,National,Oldies,Folk,Documentary,Alarm Test,Alarm" 'SETUP pwmfreq 32132 modes = "VOLUME, FREQ , SEEK , LIGHT, TUNE , TEST " pinA = 1 ' Encoder A pinB = 2 ' Encoder B GREEN = tft.rgb(0,255,0) GREY = tft.rgb(63,63,63) DARKGREY = tft.rgb(31,31,31) SILVER = tft.rgb(128,128,128) RED = tft.rgb(255,0,0) YELLOW = tft.rgb(255,255,0) ORANGE = TFT.rgb(255,127,0) tft.srect.round.fill(0,0,320,170,2, 0, GREY) 'VARS TIMERFAST = 500 TIMERSLOW = 2000 BL = 90 oldrssi = 0 oldmono = 5 oldstation = "MiniRadio" oldbattery = "Bat" mono = 0 mode = 1 modecnt = 0 modetxt = word(modes,mode,",") v = 50 oldv = 0 VOLUME v rot = 0 r = 0 oc = 1 synced = 0 pwmout 38,BL ' Left BOX tft.srect.round.fill(1, 1, 76, 110, 4, 65535, 0) tft.srect.round.fill(2, 2, 74, 108, 4, 0, 65535) TFT.circle.fill(45,40,20,RED) x = 3 y = 3 for i = x to x+70 step 2 tft.line(x,y,i,108,ORANGE) next i tft.text.font(1) tft.text.color(YELLOW) tft.text.cursor(0,60+20) tft.println(" Mini-") tft.println(" Radio-") tft.println(" Scripting") s = upper("MiniRadioScript ") i = 1 'STATUSBOX tft.srect.round.fill(240, 20, 76, 22, 4, 65535,0) tft.srect.round.fill(241, 21, 74, 20, 4, 0,65535) ' SCALE NUMS tft.text.color(65535,0) tft.text.datum(4) for i = 8800 to 10600 step 200 px = map(i, 8700, 10800, 0, 300) tft.text.draw(format(" %3.0f ",i/100),px+20,120+18,1) next i ' SCALE TICKS for i = 8800 to 10600 step 200 px = 1 + map(i, 8700, 10800, 0, 300) tft.line(px+20,120+12,px+20,120+12-4,65535) next i for i = 8700 to 10700 step 50 px = 1 + map(i, 8700, 10800, 0, 300) tft.line(px+20,120+8,px+20,120+12-4,65535) next i gosub [drawvolume2] gosub [drawfreq] gosub [drawstatus] interrupt pinA,[change] interrupt pinB,[change] interrupt 21,[push] Timer TIMERFAST,[timer1] Timercb TIMERSLOW,[timer2] Wait [timer1] timercb 0 gosub [drawrssi] gosub [drawtext] gosub [drawdate] timercb TIMERSLOW,[timer2] wait [timer2] timer 0 gosub [drawbattery] gosub [drawtraffic] gosub [drawtype] gosub [drawafc] timer TIMERFAST,[timer1] return ' ROTARY INTERRUPT [change] if io(laststat,pinA) = 1 then a = 1 else a = 0 if io(laststat,pinB) = 1 then b = 1 else b = 0 c = a + b '101 abc -> + rot = 0 if c = 1 and oc = 2 then if a = 1 and b = 0 then rot = 1 if a = 0 and b = 1 then rot = -1 if rot <> 0 then gosub [dorotate] endif oc = c wait ' ENCODER [dorotate] ' VOLUME if mode = 1 then if rot > 0 then v = min(v + 5, 60) if rot < 0 then v = max(v - 5, 0) ' Volume v gosub [drawvolume2] endif ' FREQ if mode = 2 then f = rx.freq() if rot > 0 then f = min(f + 0.10, 108.00) if rot < 0 then f = max(f - 0.10, 87.00) freq f station = "" tft.rect.fill(96,84,128,30,0) 'STATION tft.rect.fill(0,170-20,320,20,0) 'TEXT rot = 0 gosub [drawfreq] endif ' SEEK if mode = 3 then if rot > 0 then seekup if rot < 0 then seekdn rot = 0 station = "" tft.rect.fill(96,84,128,30,0) tft.rect.fill(0,170-20,320,20,0) rot = 0 gosub [drawfreq] endif ' LIGHT if mode = 4 then if rot > 0 then BL = min(BL + 5, 100) if rot < 0 then BL = max(BL - 5, 0) pwmout 38,BL*2 endif ' TUNE if mode = 5 then station = "" tft.rect.fill(96,84,128,30,0) tft.rect.fill(0,170-20,320,20,0) if rot > 0 then timer 0 [start5up] f = rx.freq() + 0.10 if f > 108.00 then goto [end5] freq f gosub [drawfreq] if rx.snr() > 3 then goto [end5] goto [start5up] endif if rot < 0 then timer 0 [start5dn] f = rx.freq() - 0.10 if f < 87.00 then goto [end5] freq f gosub [drawfreq] if rx.snr() > 3 then goto [end5] goto [start5dn] endif [end5] rot = 0 gosub [drawfreq] Timer 250,[timer1] endif return ' MODE CHANGE PUSH [push] if io(laststat,21) = 1 then r = 0 else r = 1 inc modecnt if (modecnt % 2) = 0 then inc mode if (mode = 6) then mode = 1 modetxt = word(modes, mode,",") endif gosub [drawstatus] wait ' DRAW UI [drawtraffic] c = SILVER if rx.stereo() <> 0 then c = RED tft.circle.fill(276-10,60+12,3,c) c = SILVER if rx.tp() <> 0 then c = tft.rgb(255,128,0) tft.circle.fill(276,60+12,3,c) c = SILVER if rx.ta() <> 0 and rx.tp() <> 0 then c = tft.rgb(255,255,0) tft.circle.fill(276+10,60+12,3,c) return [drawrssi] rssi = rx.rssi() snr = rx.snr() tft.text.color(65535,0) gosub [drawstation] if rssi = oldrssi then return x = 240 y = 60 w = 74 h = 6 tft.text.datum(4) tft.text.draw(format("SIGNAL:%02.0f/%02.0f",rssi,snr),277, 52,1) gn = 10 + map(rssi, 0, 64, 0, w / 2) gr = 2 + w - (2 * gn) tft.srect.round.fill(x + w - gn, y, gn, h, 4, GREEN,0) tft.srect.round.fill(x, y, gn, h, 4, GREEN,0) tft.srect.round.fill(x + gn - 1, y, gr + 1, h, 4, GREY,0) oldrssi = rssi return [drawstatus] if rx.stereo() = 1 then mono = 0 else mono = 1 tft.text.font(2) tft.Text.Color(65535, 0) tft.text.cursor(278 - tft.text.width(modetxt)/2,31-tft.text.height()/2) tft.print(modetxt) oldmono = mono return [drawfreq] ' FREQUENCY BIG sf = format("%5.1f ",rx.freq()) 'sf = left(sf,5) tft.text.datum(4) tft.text.color(65535,0) tft.text.draw(sf,160,60,7) if rot <> 0 then return ' SCALEBAR x = 10 y = 120 w = 300 h = 6 gn = 10 + map(rx.freq()*100, 8700, 10800, 0, w) gr = 2 + w - (1 * gn) tft.srect.round.fill(x, y, gn, h, 4, RED,0) tft.srect.round.fill(x + gn - 1, y, gr + 1, h, 4, GREY,0) return [drawvolume_old] if oldv = v then return tft.text.color(65535,0) tft.text.datum(4) tft.text.draw(format("VOL: %2.0f ",v/5),277,100,2) oldv = v volume v return [drawstation] hh = trim(rx.station()) if oldstation = hh then return if hh <> "" then station = hh tft.text.color(65535,0) tft.text.datum(4) wo = tft.text.width(oldstation) w = tft.text.width(station) if oldstation <> station then tft.rect.fill(160-80,84,156,30,0) 'STATION tft.text.draw((station),160,102,4) oldstation = station return [drawtext] h = rx.text() if h = txt then return if h<>"" then txt= h tft.text.color(TFT.rgb(255,228,0),0) tft.text.cursor(0,150-9) tft.text.font(2) tft.print(txt) return [drawbattery] batteryLevelColor = GREEN batteryvoltage = format("%04.2fV",io(adc,4)/1023*3.3*2) if batteryvoltage < "3.80V" then batteryLevelColor = tft.rgb(255,255,0) if batteryvoltage < "3.45V" then batteryLevelColor = tft.rgb(255,0,0) if oldbattery = chargeLevel then return tft.text.color(batteryLevelColor ,0) tft.text.datum(4) tft.text.draw(batteryvoltage,300,11,1) oldbattery = batteryvoltage return '"2024-04-08T10:13:24" [drawdate] tft.text.color(65535,0) if synced = 0 then tft.text.color(SILVER,0) tft.text.draw(time("hour:min"),250 + 10,11,1) d = rx.datetime() if d = "" then return d = replace(d & ":03"," ","T") d = replace(d,".","-") if left(d,1) = "2" then timeset(d) synced = 1 endif tft.text.draw(d,160,10,2) return [drawtype] i = rx.pty() if i <= 16 then s = word(rdstype1,i,",") else s = word(rdstype2,i-16,",") if oldtype <> s then tft.rect.fill(160-80,30-8,160,9+4,0) endif tft.text.color(65535) tft.text.draw(upper(s),160,27,1) oldtype = s return [drawvolume2] c = 0x3526 for i = 0 to v/5 x = 244 y = 100 tft.rect.fill(x + (i * 4), y - 12, 2, 4 + 12 -i, 0) tft.rect.fill(x + (i * 4), y - i , 2, 4 + i , c) next i if oldv > v then for i = oldv/5 to v/5 step -1 tft.rect.fill(x + (i * 4), y - 12 , 2, 12 + 4, 0) next i endif tft.text.datum(4) tft.text.color(65535,0) tft.text.draw(format("VOLUME:%2.0f ",v/5),277, y+12,1) oldv = v volume v return [drawafc] x = 276 y = 80 tft.circle.fill(x,y,3,GREEN) x = x - 12 tft.triangle.fill(x-3,y-3,x+6,y,x-3,y+3,GREEN) x = x + 24 tft.triangle.fill(x-6,y,x+3,y-3,x+3,y+3,GREEN) return