rea23 Newbie
 Joined: 16/09/2022 Location: SwitzerlandPosts: 26 |
| Posted: 10:19am 27 Nov 2022 |
|
|
|
Hi A short text, e.g. a name, is to be entered on a 2.4" display without touch screen. One possibility is shown in the listing. Maybe someone has a more elegant solution for this?

'***************************************************** ' INPUT a short text e.g. a name w/o KBD or Touch ' Use of three buttons: Left, Right and Enter ' ---------------------------------------------------- ' Display 2.4", 320 x 240 ILI9341 (from MikroShop) ' works with ILI9488 driver only (Portrait mode)! ' Colors are inverted ! (255-RGB=iRGB) ?? cheap LCD ' MMBasic on Pi Pico with USB-C and on board RGB-LED! ' Test Buzzer: ok with SUB BUZZ ' 6.10.2022: Moving Cursor: two buttons < and > ' 09.11.2022: < / > button, 3rd button for Enter ' 10.11.2022: Display limit l/r ok ' Sometimes bouncing ===> 100 nF // to switches, ok ' New name: Move over margin </>, then Enter button '*****************************************************
'OPTIONS: 'OPTION SYSTEM SPI GP18,GP19,GP16 'OPTION LCDPANEL ILI9488, P, GP15, GP14, GP13 !! false driver, but works ' setpin GP23, dout 'RGB-LED, on board SETPIN GP3, dout 'Buzzer setpin GP4, intl, move_r, pullup 'Button > setpin GP1, intl, move_l, pullup 'Button < setpin GP2, intl, take, pullup 'Button Enter, pin4, GND: pin3
' !! inverted colors because of "false" driver for LCD!! Take RGB values CONST black_= RGB(255,255,255) 'black inv. CONST green_= RGB(255,127,255) 'green inv. CONST yellow_= RGB(0,0,255) 'yellow inv.
dim letter as string length 1 'letter for name dim newname as string Dim z, no, fini, t as Integer 'counter, number, flag, toggle
print mm.ver, " RC9" print mm.info$(lcdpanel), " should be ILI9341, but then 240x240 only!?" print mm.info$(flash), " SD does not work" print mm.info$(touch), "Touch does not work" print
abc$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'choice of letters x = 148 'cursor position at begin dx = 12 'spacing ytxt = 60 'y-position of text dy = 20 'distance cursor to text no = 13 'number of letter/cursor position t = 0 'toggle
cls black_ 'display black, iRGB of (0,0,0) box 0,0,320,240,1, yellow_ 'FILL not possible on this display! FONT 2, 1 text 4, ytxt, abc$,,,, green_, black_ 'ABCDE...Z text x, ytxt+dy, "^",,2,, yellow_, black_
do do while t = 0 'wait on toggle/button pause 10 loop text x, ytxt+dy, "^",,2,, yellow_, black_ letter = mid$(abc$,no,1) if t = 1 then t=0 newname = newname + letter setpin GP2, off end if text 4, 110, newname,,2,, yellow_, black_ pause 10 setpin GP2, intl, take, pullup if fini = 1 then exit do loop text 4, 16, "New name is: "+newname,,2,, yellow_, black_ print print "New name:", newname
end '>>>>>>>>>>>>>>>>>>>>>>>>> FINITO >>>>>>>>>>>>>>>>>>>>>>>
sub move_r 'interrupt, move cursor t=0 no = no + 1 if x < (320-2*dx) then text x, ytxt+dy, " ",,2,, yellow_, black_ text x+dx, ytxt+dy, "^",,2,, yellow_, black_ x=x+dx else text x, ytxt+dy, " ",,2,, yellow_, black_ no = 33 letter = "" 'to the right, over Z fini = 1 'flag endif End sub
sub move_l 'interrupt, move cursor t=0 no = no - 1 if x > 12 then text x, ytxt+dy, " ",,2,, yellow_, black_ text x-dx, ytxt+dy, "^",,2,, yellow_, black_ x=x-dx else text x, ytxt+dy, " ",,2,, yellow_, black_ no = 33 letter = "" 'to the right, over Z fini = 1 'flag endif End sub
sub take 'interrupt to catch the letter t=1 'toggle z=z+1 'counter BUZZ(1, 100) 'buzzer 500Hz, 100 ms end sub
SUB BUZZ(freq,length) 'produces 0.5ms pulses on GP3 local i for i = 1 to length 'freq falls with higher numbers pulse GP3, 1 'freq = 0.5 is 1kHz pause freq next End sub
Edited 2022-11-27 21:32 by rea23 |