|
Forum Index : Microcontroller and PC projects : screen positions
| Author | Message | ||||
| Foxroy Newbie Joined: 09/02/2019 Location: United KingdomPosts: 6 |
Help with TOUCH I have 4 lines of code. DO TEXT 120, 120, STR$(TOUCH(X), 3) + " " + STR$(TOUCH(Y), 3) TEXT 20, 20, "Test" LOOP Problem is that the x and y reported is with x=0 and y=0 at bottom RHS of the screen, but the text "Test" is printed at the top LHS of the screen which is what I would expect. So a contact with the screen on the "Test" reports circa 320 for x and 220 for y. This is bizar? How can this happen? |
||||
goc30![]() Guru Joined: 12/04/2017 Location: FrancePosts: 435 |
hi Foxroy with my mm+ your code is good, it give good values, but it seems that there are some problems with the "TOUCH" function, but it is also better to use this function in a more complete way. It should not be forgotten that this function permanently give the x,y positions, and therefore between two instructions these data can change. first I advise you to use this function in "interrupt" mode, then to work with temporary storage variables I give you an example of use, who give x,y pos on touch down and x,y pos on touch up dim vx%,vy% dim ax%,ay% dim posdx%^posdy% dim posux%,posuy% dim flgt% 'flag touch (0=no touch, 1=touch is down, 2=touch is up CLS GUI interrupt sptouchd,sptouchu Text 20,20,"Test" flgt%=0 Do ax%=touch(x) 'first give x,y pos ay%=touch(y) if (flgt%=1 and touch(up)=false) then if (ax%<>-1 and ay%<>-1) then vx%=ax% vy%=ay% 'Text 120,210,Str$(vx%,3)+" "+Str$(vy%,3) pixel vx%,vy%,&hffffff end if end if 'Pause (10) if flgt%=2 then Text 120,120,"TD:"+Str$(posdx%,3)+" "+Str$(posdy%,3) Text 120,180,"TU:"+Str$(posux%,3)+" "+Str$(posuy%,3) flgt%=0 end if Loop Sub sptouchd() 'interrup on touch down vx%=Touch(x) vy%=Touch(y) flgt%=1 posdx%=vx% posdy%=vy% 'Print "touch down in :"; 'Print vx%,vy% end sub Sub sptouchu() 'interrupt on touch up flgt%=2 'Print "touch up in :"; 'Print vx%,vy% posux%=vx% posuy%=vy% End Sub in graphic mode, pos 0,0 is on top left for Geoffrey on Micromite+ (v5.05.02) I think that using X,Y or LastX,LastY on touch Up have a problem, because for touch(x) it is too late, it give -1, and touch(lastx) give the x pos when touch down not when touch is up. normally the good code will be that GUI interrupt sptouchd,sptouchu do:loop Sub sptouchd() print str$(touch(X));" ";str$(touch(Y)) end sub Sub sptouchu() print str$(touch(lastx));" ";str$(touch(lasty)) 'or print str$(touch(X));" ";str$(touch(Y)) with x and y value before up end sub |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
This can happen with some touch screens when you use one of the combined MMBasic + BASIC program + options firmware files. For example, I have them on my website for the "Super Clock" and "DDS Function Generator". The problem comes about because these combined firmware files were setup using a "standard" LCD panel. However some panels have the touch controller connected back to front giving symptoms like that that you have described. The fix is simple. Just rerun the touch calibration using the command GUI CALIBRATE. Geoff Graham - http://geoffg.net |
||||
goc30![]() Guru Joined: 12/04/2017 Location: FrancePosts: 435 |
Hi geoffg I run "gui calibrate" and after that, it is worst, I have no x,y pos and no interrupt on touch down, and only -1,-1 on touch up 'mm.ver = 5.05.02 beta1 'proc pic32mx470 'OPTION LCDPANEL SSD1963_5, LANDSCAPE, 12, 21 'OPTION TOUCH 18, 14 'GUI CALIBRATE 0, 4041, 0, -35922, 2147483647 'OPTION SDCARD 52 'OPTION RTC 43, 44 GUI interrupt sptouchd,sptouchu do:loop Sub sptouchd() print "D:";str$(touch(X));" ";str$(touch(Y)) end sub Sub sptouchu() print "U:";str$(touch(X));" ";str$(touch(Y)) end sub I have disable touch and reinstall (and gui calibrate), but it is same and after some others "calibrations", some times I have datas,but not good datas), and some other times, i have nothing. It seels that it is necessary to power down, disconnect console, and after only it work when it want. |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10572 |
This is correct. The touch position is only measured at the time of the interrupt when using GUI INTERRUPT. So you will get -1 on touchup for X and Y as the touch is no longer present at that time. i.e. there is nothing to measure. Likewise LASTX and LASTY will report the position when the touchdown occurred. If you want to see the movement of a "touch", this can only be done by polling X and Y dim integer td=0 GUI interrupt sptouchd,sptouchu do do while td print touch(x),touch(y) loop loop Sub sptouchd() td=1 end sub Sub sptouchu() td=0 end sub |
||||
goc30![]() Guru Joined: 12/04/2017 Location: FrancePosts: 435 |
Hi peter I undestand. My prog exemple on top of this topic, is in right line of your method but to be more easy to use "touch" function, I think that "LastX/LastY" will be beter to have the t-1 value, not first value who is a dupplicate value (you can read first value with TD interrupt) it is just an idea. If it make too many problems, you can forget my idea |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
Hi goc, I was replying to Foxroy's post. You seen to have a different issue. Geoff Graham - http://geoffg.net |
||||
| Foxroy Newbie Joined: 09/02/2019 Location: United KingdomPosts: 6 |
Hi all. Foxroy here. I think I may not have described the problem quite well enough. I was running the short piece of code (find it 1/3 way down on page 80 in the 'Getting Started..' manual). Additionally I had put an additional (possibly confusing) line in the loop. However removing the additional line and the problem is still there! A touch on the screen in the Top LH corner would report a high x and y (say 300,200) wheras a touch in the lower RH corner would report a low x and y. (say 10.10). In other words the screen x and y reports were completely diagnally opposed to what you would expect. That was the problem. However the 'text 10, 10, !!!!! command would print on the screen correctly in the top LH corner and also 'text 300, 200, !!!!! command would print correctly in the lower RH corner. So within a single line of code the x and y values are completely opposed !!! I solved the problem this morning by simply resetting the LCD with the OPTIONS and GUI commands. How it got into this state I will leave to you guys and gals to figure out as I am not clever enough to understand the combinations of commands and code to achieve this. Interesting puzzle for those clever enough? Once again many thanks for all the suggestions. Foxroy |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
It sounds as if something went wrong when you initially used the GUI CALIBRATE command. Geoff Geoff Graham - http://geoffg.net |
||||
| Foxroy Newbie Joined: 09/02/2019 Location: United KingdomPosts: 6 |
Foxroy here again. Just to be clear, I used OPTION RESET and redefined the LCD and TOUCH settings. This cleared the problem and the code now reports correctly for x and y. So somehow these setting had got corrupted, in what I would suggest, a very strange way? Foxroy |
||||
| Foxroy Newbie Joined: 09/02/2019 Location: United KingdomPosts: 6 |
I have just been able to repeat the problem. Simply put a GUI CALBRATE 0, 252, 306, 932, 730 line at the beginning of the program and hey persto !! I realise now that I should not have done this (see page 50 of the Programming Manual. But what an intersting result??? Foxroy |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
I'm not sure that is very interesting because the command is just doing what it is intended to do. More interesting is why would you do that in the first place? Geoff Graham - http://geoffg.net |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |