Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:15 01 Aug 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 : Thoughts on using touch screens

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 02:15pm 02 Apr 2018
Copy link to clipboard 
Print this post


function swipe time,min,max

Swipe
dir$= Swipe
dir$ will = U,D,L,R for maxspan movement
default maxspan is movement of 2/3 of screen
dir$ will = u,d,l,r for minspan movement
default minspan is movement of 1/2 of screen
time is minimum swipe frame less is a touch

or simple verison

dir$=swipe time
dir$ will = U,D,L,R for any thing over 1/2 screen movement
time is minimum swipe frame less is a touch

or are we locked in to the values of x and y at time of the touch interrupt.

Quazee
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 09:48pm 02 Apr 2018
Copy link to clipboard 
Print this post

As far as I know, you are locked into the value of X and Y at the time of interrupt - for now. Swipe might be something Geoff or Peter could add, but I expect it would probably not be that easy.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 10:23pm 02 Apr 2018
Copy link to clipboard 
Print this post

TOUCH(X) and TOUCH(Y) can be called at any time.
You could use an interrupt to get the starting position and then read again after a short delay.

How you do it would depend on the device and the main program flow.

Jim

VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 10:29pm 02 Apr 2018
Copy link to clipboard 
Print this post

@ Jim - Clever. And very simple.
Smoke makes things work. When the smoke gets out, it stops!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 12:05am 03 Apr 2018
Copy link to clipboard 
Print this post

Jim's solution is elegant and simple. Much better than cluttering the language with extra features with limited application.
Geoff Graham - http://geoffg.net
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:05am 03 Apr 2018
Copy link to clipboard 
Print this post

Crude but something to start with
  Quote   OPTION EXPLICIT
DIM tX, tY
SETPIN 2, INTL, tapped ' touch interrupt pin

DO

LOOP
END

SUB tapped
tX=
TOUCH(X)
tY=
TOUCH(Y)
SETTICK 300, swiped, 1 ' check in 300mS
END SUB

SUB swiped
LOCAL swX, swY, swDX, swDY
SETTICK 0, 0, 1 ' disable the timer
swX = TOUCH(X)
swY =
TOUCH(Y)
IF swX<>-1 AND swY<>-1 THEN ' pen still down
swDX = swX - tX
swDY = swY - tY
IF swDX > 30 THEN
PRINT "Swipe right"
ELSEIF swDX < -30 THEN
PRINT "Swipe left"
ELSEIF swDY > 30 THEN
PRINT "Swipe down"
ELSEIF swDY < -30 THEN
PRINT "Swipe up"
ELSE
PRINT "Little swipe"
ENDIF
ELSE
PRINT "Tapped"
ENDIF
END SUB

The 300mS time will need adjusting as well as the 30 pixel dead zones

Works on a MX170 and ILI9341 display.

Jim
VK7JH
MMedit
 
Quazee137

Guru

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

My Granddaughter was asking. She lives on her phone and drawing tablet.
The really nice computer we got her has dust and cobwebs. I may highjack it.

Flipping around screens is something she wanted to do with the Micromite
she plays with.

Thanks TassyJim

I'll pass the code on to her and see what artful things she does with it.

Could this be a C-function? Asking as I don't do C.

On the controllers they wanted bigger touch zones so . . .
Instead of testing start xxx/yyy end xxx/yyy for object detection.
This predefines the object size and uses the itx/ity or
icx/icy with pendown gives a row col like row 2 col 5
easy for select case. The keyboard function I posted uses this way.
(now how do I to point to post? )

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

Sub touched
tx=Touch(x):ty=Touch(y)
If tx=-1 Then Exit Sub
If ty=-1 Then Exit Sub
itx=(tx\32):ity=(ty\24) ' 10 by 10
icx=(tx\64):icy=(ty\48) ' 5 by 5
PenDown=1:PenUp=0
End Sub

Sub untouched
PenDown=0:PenUp=1
End Sub

Thanks Quazee


TassyJim just tried the code on a 4" Hat Stand works.
Like you said need to tune it a bit, 400 did better.
She'll be very happy to play with it.

Edited by Quazee137 2018-04-04
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 09:37pm 03 Apr 2018
Copy link to clipboard 
Print this post

or another take - without touching your screen, control your 'mite like a jedi https://www.ebay.co.uk/itm/APDS-9960-GY-9960-Digital-RGB-Ambient-Light-Proximity-Gesture-Sensor-Module/202068693590?hash =item2f0c3b9256:g:YH8AAOSwNpBZzmyg
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 03:54pm 11 Apr 2018
Copy link to clipboard 
Print this post


Jim thanks for getting this going for her.

Here is what she is playing with.


'Hat Stand with 4" LCD
Option EXPLICIT
Dim tX, tY, PenDown,swipe$
SetPin 5, INTL, touched ' touch interrupt pin
SetPin 5, inth,untouched
Font 1,2
Color RGB(yellow),RGB(blue)

CLS
Do
Select Case swipe$
Case "U"
Text 10,100,"Going Up a screen "
Case "D"
Text 10,100,"Going Down a screen "
Case "L"
Text 10,100,"Going to screen on Left "
Case "R"
Text 10,100,"Going to screen on Right"
Case "T"
Text 10,100,"Just a Touch "
End Select
Loop
End

Sub touched
tX=Touch(X)
tY=Touch(Y)
PenDown=1
SetTick 400, swiped, 1 ' check in 400mS
End Sub

Sub untouched
PenDown=0
End Sub

Sub swiped
Local swX, swY, swDX, swDY,swXS,swYS
SetTick 0, 0, 1 ' disable the timer
swX = Touch(X)
swY = Touch(Y)
If pendown Then ' pen still down
swDX = (swX - tX)
swDY = (swY - tY)
swXS=Sgn(swDX):swDX=Abs(swDX)
swYS=Sgn(swDY):swDY=Abs(swDY)
End If

If (swDX > swDy) And swXS=1 Then swipe$="R"
If (swDX > swDy) And swXS=-1 Then swipe$="L"
If (swDX < swDy) And swYS=1 Then swipe$="D"
If (swDX < swDy) And swYS=-1 Then swipe$="U"
If swDX+swDY <30 Then swipe$="T"

End Sub


Jim Thanks again
Quazee

 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9610
Posted: 11:48pm 11 Apr 2018
Copy link to clipboard 
Print this post

If she is not a member here already, please encourage her to join. Heaps of people to offer help here, and then you would not need to act as a message relay.

....or you might not mind doing that.
Smoke makes things work. When the smoke gets out, it stops!
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 593
Posted: 09:02am 14 Apr 2018
Copy link to clipboard 
Print this post



@grogster I told her she should.

Well I guess she is not ready to show her raw code to anyone else.

Here is a bit she added to turn swipe on and off


Sub touched
tX=Touch(X)
tY=Touch(Y)
PenDown=1
If swipe$<>"N" Then SetTick 400, swiped, 1
End Sub


Thanks again Jim she is having fun playing with 9 screens
she can flip to. (Im waiting on her trying to do the diagonals)

Quazee
 
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