Quazee137
 Guru
 Joined: 07/08/2016 Location: United StatesPosts: 593 |
Posted: 11:34pm 07 Oct 2016 |
Copy link to clipboard |
 Print this post |
|
A tiny keyboard test using = as RET, < as BS and touching the text area as clr.
Print "LCD Backpack 3" Print "tiny keyboard.bas" Option base 1
RTC gettime SetPin 15, intl,touched
Dim rcolor(2) = (RGB(red),RGB(yellow)) Colour RGB(blue), RGB(blue) Dim my$=""
CLS Font 1, 2 Box 0, 0, MM.HRes-1, MM.VRes/2-10, 8, , RGB(yellow)
initkb
Do
If kp Then Select Case k$
Case "=" Print my$ Text 9,MM.VRes/6," ",,1,2,RGB(red),RGB(yellow) my$=""
Case "<" 'Print "you pressed BS" If Len(my$)<>0 Then my$=Left$(my$,Len(my$)-1)
Case Chr$(12) 'Print "clear LCD text area" Text 9,MM.VRes/6," ",,1,2,RGB(red),RGB(yellow) my$=""
Case Else If Len(my$)<17 Then my$=my$+k$
End Select
Text 9,MM.VRes/6,my$+"_ ",,1,2,RGB(red),RGB(yellow) kp=0
End If
' This is where the main work is to be done.
Text MM.HRes/2,30,Date$+" "+Time$,cm,1,2,RGB(red),RGB(yellow)
Loop
Sub touched tx=Touch(x):ty=Touch(y)-yos itx=(tx\32)+1:ity=(ty\32)-2
If (tx<1) Or (ty<1) Then Exit Sub ' touch text area to clear k$=Chr$(12) kp=1
PWM 2,1200,55:Pause 50:PWM 2,STOP 'Beep
If Not (ty =>100) Then Exit Sub
Text 10+(itx-1)*32,4+(ity+2)*32+yos,key$(itx,ity),,,,RGB(black),RGB(white)
Do While Touch(x) <> -1: Loop
Text 10+(itx-1)*32,4+(ity+2)*32+yos,key$(itx,ity),,,,RGB(black),RGB(brown)
k$=key(itx,ity)
End Sub
Sub initkb
Dim string key(10,4)= ("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
yos=15
For y=1 To 4 For x=1 To 10 RBox (x-1)*32,(y+2)*32+yos, 32, 32,,RGB(yellow),RGB(brown) 'a quick patch for the space bar If key(x,y)=" " Then RBox (4)*32,(6)*32+yos, 64, 32,,RGB(yellow),RGB(brown) Text 10+(x-1)*32,4+(y+2)*32+yos,key(x,y),,,,RGB(black),RGB(brown) Next x Next y
End Sub
 Edited by Quazee137 2016-10-13 |