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 : Maximite Sketch
Author | Message | ||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
A quick and nasty sketch program to make use of my new touch screen. My drawing skills are somewhat limited. (converted from BMP to GIF to upload) Still needs a lot of work but I am beginning to understand the needs of a touch screen controller. Jim VK7JH MMedit MMBasic Help |
||||
OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 926 |
Good job TassyJim, look forward to see where you go with this one. |
||||
Lopezjm2001 Regular Member Joined: 08/07/2012 Location: AustraliaPosts: 42 |
Hi Jim, I am looking at installing a touch screen for 7" LCD screen with a Duinomite Mega. I saw your program on your thread - Small VGA Monitor and will use your implementation. Can you share the mmbasic program you used to make the sketch drawing above. I am assuming you wrote the program in mmbasic. Thanks, John Lopez Lopez |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
This is the program. You will need to uncomment the call to the calibration subroutine and then change the values for Xslope, Xi, Yslope and Yi. I found that I needed a resistor in series with the Y axis to keep the current draw down. The X axis at 700 ohms was OK as is. ' touch display demo
' by TassyJim ' 16 Nov 2012 ' see the XPT2046 or ADS7843 data sheets for a description ' of how the resistive touch screen works cls dim cal(4,2) dim Mrepeat(15) TouchX1=10 ' 4 analogue input pins for the resistors TouchX2=8 TouchY1=9 TouchY2=7 TouchIntEnable=34 ' any digital output pin TouchInt=28 ' digital interupt pin Xslope=166.557 Xi=-17.196 Yslope=248.08 Yi=-268.885 sz=2 col=2 drawmode=1 setpin TouchInt, 2 gosub _menuMain 'gosub _TouchCalibrate gosub _touchEnable settick 100, _Touched setpin TouchX2, 8 Pin(TouchX2)=0 _mainMenuLoop: 'do stuff while waiting for a touch if (Xhit+Yhit) > 0 then 'XhitO=Xhit : YhitO=Yhit if Xhit>=400 then M=int(Yhit/43)+1 if M>6 then if Xhit>439 then M=M+4 if Mrepeat(M)=0 then for n = 1 to 14 Mrepeat(n)=0 next n endif Mrepeat(M)=Mrepeat(M)+1 if Mrepeat(M)>2 then on M goto _Mu1,_Mu2,_Mu3,_Mu4,_Mu5,_Mu6,_MU7,_MU7,_MU7,_MU7,_MU7,_MU7, _MU7,_MU7 endif on drawMode goto _Mu4,_Mu5 endif goto _mainMenuLoop _touchEnable: setpin TouchY1, 1 setpin TouchY2, 1 setpin TouchX1, 1 setpin TouchX2, 8 Pin(TouchX2)=0 setpin TouchIntEnable, 8 pin(TouchIntEnable)=1 'pause 5 'setpin TouchInt, 7, _Touched 't=0 return _Touched: pin(0)=1 if pin(TouchInt)=0 then ' touch still there setpin TouchIntEnable,0 ' disable the interupt resistor gosub _readTouch gosub _touchEnable else Xhit=0 ' so set the results to zero Yhit=0 endif font 1,1 if (Xhit+Yhit) > 0 then print @(340,400)" " print @(340,400)Xhit;" ";Yhit endif pin(0)=0 ireturn _readTouch: 'setpin TouchInt, 0 setpin TouchY1, 1 setpin TouchY2, 1 'setpin TouchX1, 1 setpin TouchX2, 8 Pin(TouchX2)=0 setpin TouchX1, 8 ' Pin(TouchX1)=1 ' X1 is now high and X2 low pause 1 Xvolt=pin(TouchY1) ' read the X position using Y1 'pause 3 'Xvolt=pin(TouchY1) ' read the X position again setpin TouchX1, 1 setpin TouchX2, 1 ' set the X as input setpin TouchY1, 8 ' and the Y as potential divider setpin TouchY2, 8 Pin(TouchY1)=1 Pin(TouchY2)=0 pause 1 Yvolt=pin(TouchX1) ' read the Y position using X1 'pause 3 'Yvolt=pin(TouchX1) ' read the Y position again Xhit=int(Xi + Xvolt*Xslope) 'int(mm.hres*Xvolt/3.3) ' you can scale to any value here Yhit=int(Yi + Yvolt*Yslope) 'int(mm.vres*Yvolt/3.3) if Xhit >500 or Yhit < -15 then 'reading is suspect Xhit=0 ' so set the results to zero Yhit=0 endif return _TouchCalibrate: circle (10,10),4,6,F gosub _touchEnable while t=0 wend cal(1,1)=Xvolt cal(1,2)=Yvolt circle (470,10),4,6,F pause 1000 gosub _touchEnable while t=0 wend cal(2,1)=Xvolt cal(2,2)=Yvolt circle (10,420),4,6,F pause 1000 gosub _touchEnable while t=0 wend cal(3,1)=Xvolt cal(3,2)=Yvolt circle (470,420),4,6,F pause 1000 gosub _touchEnable while t=0 wend cal(4,1)=Xvolt cal(4,2)=Yvolt cal(1,1)=(cal(1,1)+cal(3,1))/2 cal(1,2)=(cal(1,2)+cal(2,2))/2 cal(2,1)=(cal(2,1)+cal(4,1))/2 cal(2,2)=(cal(3,2)+cal(4,2))/2 Xslope=460/(cal(2,1)-cal(1,1)) Xi=10 - cal(1,1)*Xslope Yslope=410/(cal(2,2)-cal(1,2)) Yi=10 - cal(1,2)*Yslope print Xslope;" ";Xi print Yslope;" ";Yi return _menuMain: gosub _drawMenuBox font 1, 2 print @(405,1*43-25)"New" print @(405,2*43-25)"Load" print @(405,3*43-25)"Save" print @(405,4*43-25)"Free" print @(405,5*43-25)"Line" print @(405,6*43-25)"Size" for n = 7 to 10 line (401,(n-1)*43+1) - (439,n*43),n-7, BF line (441,(n-1)*43+1) - (479,n*43),n-3, BF next n line (440,301) - (440,430),6 return _drawMenuBox: for n = 1 to 10 line (400,(n-1)*43) - (479,n*43),6, B next n return _Mu1: ' new pause 120 if Xhit>400 and Yhit<43 then line (1,1) - (399,431),0,BF gosub _menuMain endif goto _mainMenuLoop _Mu2: ' load goto _mainMenuLoop _Mu3: ' save savebmp "sketch.bmp" goto _mainMenuLoop _Mu4: 'freehand drawMode=1 if Xhit+Yhit >0 then if Xhit >=400 then goto _mainMenuLoop circle (Xhit,Yhit),sz,col,F endif goto _Mu4 _Mu5: ' line drawMode=2 goto _mainMenuLoop _Mu6: ' size if Xhit>440 then sz=sz+1 if Sz=5 then sz=4 else sz=sz-1 if sz=0 then sz=1 endif goto _mainMenuLoop _Mu7: ' size col=M-7 print @(340,420)M;" " goto _mainMenuLoop Jim VK7JH MMedit MMBasic Help |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Jim, Another great candidate for the MMBasic Library. Greg |
||||
shoebuckle Senior Member Joined: 21/01/2012 Location: AustraliaPosts: 189 |
TassyJim, Would you like to zip a package with program, schematic and description for the User Library? You can send it to me at mmlib@geoffg.net. Cheers, Hugh |
||||
Lopezjm2001 Regular Member Joined: 08/07/2012 Location: AustraliaPosts: 42 |
Thanks. Lopez |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
I have to redraw the schematic and write a description. I also want to code a menu system which might be useful as a front end for various apps. I have a lot of personal things going on at the moment so it will be a few weeks before I can get it done. Jim VK7JH MMedit MMBasic Help |
||||
Print this page |