Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:27 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Testing my keyboard function

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 05:48am 06 Mar 2018
Copy link to clipboard 
Print this post

I did this as it works as is on all the LCDs I have 2.4, 2.8, 3.5, 4.0
puts it in the upper left of the larger displays. Sill raw but felt
with all those here have shared. my little bit back.


Option base 1
PWM 2, 250,20 ' back light to 25%
SetPin 15, intl,touched
SetPin 15, inth,untouched
Colour RGB(blue), RGB(yellow)
Dim key$(45)=("1","2","3","4","5","6","7","8","9","0",".","q","w","e","r","t",
"y","u","i","o","p","*","a","s","d","f","g","h","j","k","l",":","/","z","x","c",
"v","b","n","m","#","%","^","^"," ") length 1
Font 1,2
Do
'
main do
CLS
Text 10,100,"Touch Screen",,1,3
Pause 100
Do:Loop Until pendown
Do
myt$=keybd$("A mix of Text")
Loop Until myt$<>""
Do
myw$=keybd$("7 day or 28 day")
Loop Until myw$="7" Or myw$="28"
Do
myf$=keybd$("Use Flow switch y/n")
Loop Until myf$="y" Or myf$="n"
Do
myr$=keybd$("relay 1 to 4")
Loop Until Instr( 1,"1234",myr$)<>0
Do
myd$=keybd$("Duration 000 to 999")
Loop Until (Len(myd$)=3 And isnum(Mid$(myd$,1,1)) And isnum(Mid$(myd$,2,1))
And isnum(Mid$(myd$,3,1)))
Do
mys$=keybd$("00:00 to 23:59")
Loop Until validtime(mys$)
CLS
Text 0,25,myt$
Text 0,50,myw$
Text 0,75,myf$
Text 0,100,myr$
Text 0,125,myd$
Text 0,150,mys$
Text 0,200,"Touch Screen to Continue",,1,1
Do:Loop Until pendown
Loop '
main loopFunction validtime(t$)
validtime=0
If Len(t$)<>5 And Mid$(t$,3,1)=":" Then Exit Function
If Not(isnum(Mid$(t$,5,1))) Then Exit Function '0...9
If Not(Instr(1,"012345",Mid$(t$,4,1))) Then Exit Function '0...5
If Not(Instr(1,"012",Mid$(t$,1,1))) Then Exit Function ' 0..2
If Mid$(t$,1,1)="2" And Not(Instr(1,"0123",Mid$(t$,2,1))) Then Exit Function
'0..3
If Instr(1,"01",t$) And Not(isnum(Mid$(t$,2,1))) Then Exit Function
validtime=1
End Function
Function isnum(n$)
isnum = Instr(1,"0123456789",n$)>0
End Function
Sub touched
tx=Touch(x):ty=Touch(y)
If tx=-1 Then Exit Sub
If ty=-1 Then Exit Sub
itx=(tx\29):ity=(ty\34)
PenDown=1:penup=0
End Sub
Sub untouched
PenDown=0:penup=1
End Sub
Function keybd$(msg As string) As string
kbuff$=""
CLS RGB(blue)
Do
RBox
Text
RBox
Text
0,1, 319, 33,6,RGB(yellow),RGB(blue)
6,2,msg$,l,,,RGB(yellow),RGB(blue)
0,34, 319, 33,6,RGB(black),RGB(yellow)
6,35,kbuff$+" ",l,,,RGB(black),RGB(yellow)
idx=1
For y=2 To 5:For x=0 To 10
RBox x*29,y*34, 29, 34,6,RGB(black),RGB(yellow)
Text x*29+7,y*34+3,key$(idx),,,,RGB(blue),RGB(yellow)
idx=idx+1
Next x:Next y
Text 305,118,"Bs",cm,,1,RGB(blue),RGB(yellow) 'small Bs text
RBox 261,170,58,34,6,RGB(black),RGB(yellow)
' Shift box
Text 290,185,"Shift",cm,,1,RGB(blue),RGB(yellow)
RBox 0,6*34, 319, 34,20,RGB(black),RGB(yellow) 'space bar
'will need to set timmer so no touch in say 50 sec's we exit/err/restart pgm
Do While penup: Loop ' look for touch
Do While pendown:Loop ' look for no touchPause 50
idx=1 'index into char array
Select Case ity ' extract line touched
Case 0,1
keybd$ = kbuff$ 'touching upper text area is EnterKey
Exit Function
Case 2
idx = idx+itx '1st row of keys
Case 3
idx = idx+itx+11 '2nd
Case 4
idx = idx+itx+22 '3rd
Case 5
idx = idx+itx+33 '4th
Case 6
idx=45 'spacebar
End Select
k$=key$(idx)
Select Case key$(idx)
Case "a" To "z" ' shiftables
If sf=32 Then
k$=Chr$(Asc(k$)-sf)
sf=0
EndIf
If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$
Case "0" To "9",".","#","%",":","/"," " 'last part customize by need
If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$
Case "^"
sf=32
' shift flag
Case "*" ' backspace
If Len(kbuff$) >1 Then
kbuff$=Left$(kbuff$,Len(kbuff$)-1)
ElseIf Len(kbuff$)=1 Then
kbuff$=""
EndIf
End Select
Loop
End Function


here is a zipped pdf. how do we add pdf's here?
2018-03-06_154751_kf-test.pdf.zip


Edited by Quazee137 2018-03-07
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 979
Posted: 08:29pm 06 Mar 2018
Copy link to clipboard 
Print this post

Hi,

thanks for sharing!
I have a Backpack170 from Bigmick. Can you tell me what I need to set so that it works with this board?

I used:
OPTION LCDPANEL ILI9341,L,4,5,6
OPTION TOUCH 7,2
GUI CALIBRATE

Calibration was ok.

I can read "Touch Screen" on my display and that's it...

EDIT: I used MM.VER 5.0408 with a 2.4" display...

FrankEdited by Frank N. Furter 2018-03-08
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 04:27am 07 Mar 2018
Copy link to clipboard 
Print this post


change

SetPin 15, intl,touched
SetPin 15, inth,untouched

to

SetPin 7, intl,touched
SetPin 7, inth,untouched

should do it.

The testing code is by my Granddaughter. Every now and then she likes
to tinker with the mite here.


 
GoodToGo!

Senior Member

Joined: 23/04/2017
Location: Australia
Posts: 188
Posted: 07:25am 07 Mar 2018
Copy link to clipboard 
Print this post

Looks good Quazee!
I had to change a couple of lines to get it to run on my Explore100 but it works nicely. See below:-
Option base 1
'PWM 2, 250,20 ' back light to 25% '(Not required on Explore 100)
'SetPin 15, intl,touched '(Not required on Explore 100)
'SetPin 15, inth,untouched '(Not required on Explore 100)
gui interrupt touched, untouched 'For MM+ (tested on Explore 100)
Colour RGB(blue), RGB(yellow)
Dim key$(45)=("1","2","3","4","5","6","7","8","9","0",".","q","w","e","r","t","y","u","i","o","p","*","a","s","d","f","g","h ","j","k","l",":","/","z","x","c","v","b","n","m","#","%","^","^"," ") length 1
Font 1,2
Do ' main do
CLS
Text 10,100,"Touch Screen",,1,3
Pause 100
Do:Loop Until pendown
Do
myt$=keybd$("A mix of Text")
Loop Until myt$<>""
Do
myw$=keybd$("7 day or 28 day")
Loop Until myw$="7" Or myw$="28"
Do
myf$=keybd$("Use Flow switch y/n")
Loop Until myf$="y" Or myf$="n"
Do
myr$=keybd$("relay 1 to 4")
Loop Until Instr( 1,"1234",myr$)<>0
Do
myd$=keybd$("Duration 000 to 999")
Loop Until (Len(myd$)=3 And isnum(Mid$(myd$,1,1)) And isnum(Mid$(myd$,2,1)) And isnum(Mid$(myd$,3,1)))
Do
mys$=keybd$("00:00 to 23:59")
Loop Until validtime(mys$)
CLS
runText 0,25,myt$
Text 0,50,myw$
Text 0,75,myf$
Text 0,100,myr$
Text 0,125,myd$
Text 0,150,mys$
Text 0,200,"Touch Screen to Continue",,1,1
Do:Loop Until pendown
Loop ' main loop

Function validtime(t$)
validtime=0
If Len(t$)<>5 And Mid$(t$,3,1)=":" Then Exit Function
If Not(isnum(Mid$(t$,5,1))) Then Exit Function '0...9
If Not(Instr(1,"012345",Mid$(t$,4,1))) Then Exit Function '0...5
If Not(Instr(1,"012",Mid$(t$,1,1))) Then Exit Function ' 0..2
If Mid$(t$,1,1)="2" And Not(Instr(1,"0123",Mid$(t$,2,1))) Then Exit Function '0..3
If Instr(1,"01",t$) And Not(isnum(Mid$(t$,2,1))) Then Exit Function
validtime=1
End Function

Function isnum(n$)
isnum = Instr(1,"0123456789",n$)>0
End Function

Sub touched
tx=Touch(x):ty=Touch(y)
If tx=-1 Then Exit Sub
If ty=-1 Then Exit Sub
itx=(tx\29):ity=(ty\34)
PenDown=1:penup=0
End Sub

Sub untouched
PenDown=0:penup=1
End Sub

Function keybd$(msg As string) As string
kbuff$=""
CLS RGB(blue)
Do
RBox 0,1, 319, 33,6,RGB(yellow),RGB(blue)
Text 6,2,msg$,l,,,RGB(yellow),RGB(blue)
RBox 0,34, 319, 33,6,RGB(black),RGB(yellow)
Text 6,35,kbuff$+" ",l,,,RGB(black),RGB(yellow)
idx=1
For y=2 To 5:For x=0 To 10
RBox x*29,y*34, 29, 34,6,RGB(black),RGB(yellow)
Text x*29+7,y*34+3,key$(idx),,,,RGB(blue),RGB(yellow)
idx=idx+1
Next x:Next y
Text 305,118,"Bs",cm,,1,RGB(blue),RGB(yellow) 'small Bs text
RBox 261,170,58,34,6,RGB(black),RGB(yellow) ' Shift box
Text 290,185,"Shift",cm,,1,RGB(blue),RGB(yellow)
RBox 0,6*34, 319, 34,20,RGB(black),RGB(yellow) 'space bar
'will need to set timer so no touch in say 50 sec's we exit/err/restart pgm
Do While penup: Loop ' look for touch
Do While pendown:Loop ' look for no touch
Pause 50
idx=1 'index into char array
Select Case ity ' extract line touched
Case 0,1
keybd$ = kbuff$ 'touching upper text area is EnterKey
Exit Function
Case 2 '1st row of keys
idx = idx+itx
Case 3 '2nd
idx = idx+itx+11
Case 4 '3rd
idx = idx+itx+22
Case 5 '4th
idx = idx+itx+33
Case 6 'spacebar
idx=45
End Select
k$=key$(idx)
Select Case key$(idx)
Case "a" To "z" ' shiftables
If sf=32 Then
k$=Chr$(Asc(k$)-sf)
sf=0
EndIf
If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$
Case "0" To "9",".","#","%",":","/"," " 'last part customize by need
If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$
Case "^" ' shift flag
sf=32
Case "*" ' backspace
If Len(kbuff$) >1 Then
kbuff$=Left$(kbuff$,Len(kbuff$)-1)
ElseIf Len(kbuff$)=1 Then
kbuff$=""
EndIf
End Select
Loop
End Function


Cheers!
GTG!
...... Don't worry mate, it'll be GoodToGo!
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 979
Posted: 08:02am 07 Mar 2018
Copy link to clipboard 
Print this post

Hi Quazee137,

thanks for your response!

I tried

SetPin 7, intl,touched
SetPin 7, inth,untouched

before, but I get an error:

[5] SetPin 7, intl,touched
Error: Pin 7 is reserved on startup

Frank
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 08:54am 07 Mar 2018
Copy link to clipboard 
Print this post


Hi Frank

My backpack from Bigmick is setup like this

OPTION LCDPANEL ILI9341, LANDSCAPE, 4, 5, 6
OPTION TOUCH 7, 2

this will do it

SetPin 2, intl,touched
SetPin 2, inth,untouched

Quazee
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 979
Posted: 11:01am 07 Mar 2018
Copy link to clipboard 
Print this post

Hi Quazee,

thank you very much! Now it works!


Frank
 
SteveA
Regular Member

Joined: 10/03/2017
Location: United Kingdom
Posts: 48
Posted: 11:52am 07 Mar 2018
Copy link to clipboard 
Print this post

Very cool, to get it running on MM+ using the Silicon Chip Explore 64 PCB change the first few lines to:

Option base 1
PWM 2, 1000, 50 ' back light
GUI INTERRUPT touched, untouched
Colour RGB(blue), RGB(yellow)
Dim key$(45)=("1","2","3","4","5","6","7","8","9","0",".","q","w","e","r","t","y","u","i","o","p","*","a","s","d","f","g","h ","j","k","l",":","/","z","x","c","v","b","n","m","#","%","^","^"," ") length 1
Font 1,2


For some reason MMedit doesn't like key$ split over several lines, I can't see any hidden control characters, so I don't know why. But making it one long line works!
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 07:21pm 07 Mar 2018
Copy link to clipboard 
Print this post


Hi Frank
Glad it works.

Yes Steve the key$ is one long line.

Quazee
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 600
Posted: 10:59am 03 Aug 2018
Copy link to clipboard 
Print this post

While exploring the vartable I found that I was using the "length" wrong

so here's an update of the keyboard function test code.

Having length work as it should makes a big deference ram usage.
====================================
with out length 1 or using it wrong
> memory
Flash:
4K ( 5%) Program (159 lines)
56K (95%) Free

RAM:
11K (22%) 2 Variables
0K ( 0%) General
39K (78%) Free
====================================
with length 1 and using it right
> memory
Flash:
4K ( 5%) Program (159 lines)
56K (95%) Free

RAM:
1K ( 1%) 2 Variables
0K ( 0%) General
49K (99%) Free
====================================


Print MM.Ver,MM.Device$
Print "keyboard-function-12-07-2018.bas"
' fixed the "length" to the right usage, before initialising key$ array
Option base 1

'use your touch interrupt pin ----
SetPin 2, intl,touched '<-- here
SetPin 2, inth,untouched '<-- here

'gui interrupt touched, untouched
'For MM+ (tested on Explore 100) Thanks GoodToGo!
' (tested on Explore 64 PCB) Thanks SteveA

Colour RGB(blue), RGB(yellow)
Dim key$(45) length 1 = ("1","2","3","4","5","6","7","8","9","0",".","q","w","e","r","t","y","u","i","o","p","*","a","s","d","f","g","h","j","k" ,"l",":","/","z","x","c","v","b","n","m","#","%","^","^"," ")
Font 1,2

Do ' main do
CLS
Text 10,100,"Touch Screen",,1,3
Pause 100
Do:Loop Until pendown
Do
myt$=keybd$("A mix of Text")
Loop Until myt$<>""

Do
myw$=keybd$("7 day or 28 day")
Loop Until myw$="7" Or myw$="28"

Do
myf$=UCase$(keybd$("Use Flow switch Y/N"))
Loop Until myf$="Y" Or myf$="N"

Do
myr$=keybd$("relay 1 to 4")
Loop Until Instr( 1,"1234",myr$)<>0

Do
myd$=keybd$("Duration 000 to 999")
Loop Until (Len(myd$)=3 And isnum(Mid$(myd$,1,1)) And isnum(Mid$(myd$,2,1)) And isnum(Mid$(myd$,3,1)))

Do
mys$=keybd$("00:00 to 23:59")
Loop Until validtime(mys$)

CLS
Text 0,25,myt$
Text 0,50,myw$
Text 0,75,myf$
Text 0,100,myr$
Text 0,125,myd$
Text 0,150,mys$
Text 0,200,"Touch Screen to Continue",,1,1
Do:Loop Until pendown

Loop ' main loop

Function validtime(t$)
validtime=0
If Len(t$)<>5 And Mid$(t$,3,1)=":" Then Exit Function
If Not(isnum(Mid$(t$,5,1))) Then Exit Function '0...9
If Not(Instr(1,"012345",Mid$(t$,4,1))) Then Exit Function '0...5
If Not(Instr(1,"012",Mid$(t$,1,1))) Then Exit Function ' 0..2
If Mid$(t$,1,1)="2" And Not(Instr(1,"0123",Mid$(t$,2,1))) Then Exit Function '0..3
If Instr(1,"01",t$) And Not(isnum(Mid$(t$,2,1))) Then Exit Function
validtime=1
End Function

Function isnum(n$)
isnum = Instr(1,"0123456789",n$)>0
End Function

Sub touched
tx=Touch(x):ty=Touch(y)
If tx=-1 Then Exit Sub
If ty=-1 Then Exit Sub
itx=(tx\29):ity=(ty\34)
PenDown=1:PenUp=0
End Sub

Sub untouched
PenDown=0:PenUp=1
End Sub

Function keybd$(msg As string) As string

kbuff$=""
CLS RGB(blue)

Do
RBox 0,1, 319, 33,6,RGB(yellow),RGB(blue)
Text 6,2,msg$,l,,,RGB(yellow),RGB(blue)
RBox 0,34, 319, 33,6,RGB(black),RGB(yellow)
Text 6,35,kbuff$+" ",l,,,RGB(black),RGB(yellow)

idx=1
For y=2 To 5:For x=0 To 10
RBox x*29,y*34, 29, 34,6,RGB(black),RGB(yellow)
Text x*29+7,y*34+3,key$(idx),,,,RGB(blue),RGB(yellow)
idx=idx+1
Next x:Next y
Text 305,118,"Bs",cm,,1,RGB(blue),RGB(yellow) 'small Bs text
RBox 261,170,58,34,6,RGB(black),RGB(yellow) ' Shift box
Text 290,185,"Shift",cm,,1,RGB(blue),RGB(yellow)
RBox 0,6*34, 319, 34,20,RGB(black),RGB(yellow) 'space bar

'will need to set timmer so no touch in say 50 sec's we exit function
Do While penup: Loop ' look for touch
Do While pendown:Loop ' look for no touch
Pause 50

idx=1 'index into char array
Select Case ity ' extract line touched

Case 0,1
keybd$ = kbuff$ 'touching upper text area is EnterKey
Exit Function

Case 2 '1st row of keys
idx = idx+itx

Case 3 '2nd
idx = idx+itx+11

Case 4 '3rd
idx = idx+itx+22

Case 5 '4th
idx = idx+itx+33

Case 6 'spacebar
idx=45

End Select
k$=key$(idx)
Select Case key$(idx)

Case "a" To "z" ' shiftables
If sf=32 Then
k$=Chr$(Asc(k$)-sf)
sf=0
EndIf

If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$

Case "0" To "9",".","#","%",":","/"," " 'last part customize by need
If Len(kbuff$) =<15 Then kbuff$=kbuff$+k$

Case "^" ' shift flag
sf=32

Case "*" ' backspace
If Len(kbuff$) >1 Then
kbuff$=Left$(kbuff$,Len(kbuff$)-1)
ElseIf Len(kbuff$)=1 Then
kbuff$=""
EndIf

End Select

Loop

End Function


Edited by Quazee137 2018-08-04
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025