![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
IF on the Micromite+ you have OPTION TOUCH 50, 51 If I use IF TOUCH(X) <> -1 does this mean that if the screen is touched in the area referred to in the program before this command it will detect the touch? ie can I use IF TOUCH(X) <> -1 to detect a touch in a specified area? (reading the manual but it's a bit complex for me) |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
In your Switch.BAS file, the TouchDown SUB has no END SUB ![]() |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Ditto Lewis35.BAS |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Phil It wont work anyway, GUI controls won't work with non GUI controls, so I'm trying a different way. CLS clears the screen, is it possible to clear a specific section of screen instead of the whole screen? EDIT: How do I get the touch to work in a specific section of screen? At the moment I have this [code] BOX 270, 0, 280, 30, 2, RGB(white),RGB(brown) DO TEXT 410,15, "Weather|Forecast", CM, 3, 1, RGB(CYAN), DBlue IF TOUCH(X) <> -1 THEN Print "TOUCHED"[/code] It works great, but I can touch anywhere on the screen and it will detect the touch I'd like it to only detect it in the BOX |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
If you look at the code in this thread it shows one way of doing touch input using basic graphics - there are lots of others. I've extracted the concept below: I set up the coordinates of some buttons ' set up the coordinates of the buttons
dim INTEGER pos1(3)=(2,180,57,57) dim INTEGER pos2(3)=(61,180,58,57) dim INTEGER pos3(3)=(121,180,57,57) dim INTEGER pos4(3)=(2,121,57,57) dim INTEGER pos5(3)=(61,121,58,57) dim INTEGER pos6(3)=(121,121,57,57) dim INTEGER pos7(3)=(2,62,57,57) dim INTEGER pos8(3)=(61,62,58,57) dim INTEGER pos9(3)=(121,62,57,57) ' I use a single a routine to check if a specific area of the screen was touched function testtouch(position() as integer) as integer 'check touch input against screen area
if touch(x)>=position(0) and touch(y)>=position(1) and touch(x)<=position(0)+position(2) and touch(y)<=position(1)+position(3) then testtouch=1 else testtouch=0 endif end function and then there is an interrupt routine triggered by the touch that see which button is active and do whatever. Ignore the code after the "THEN"s replace it with yours. sub touchint 'touch interrupt
if testtouch(pos1()) then dosomething("1") if testtouch(pos2()) then dosomething("2") if testtouch(pos3()) then dosomething("3") if testtouch(pos4()) then dosomething("4") if testtouch(pos5()) then dosomething("5") if testtouch(pos6()) then dosomething("6") if testtouch(pos7()) then dosomething("7") if testtouch(pos8()) then dosomething("8") if testtouch(pos9()) then dosomething("9") end sUB |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Peter, that will help greatly |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
If I have a picture on a SSD1963 LCD that is 600 X 480 pixels in size on one part of the screen and the other section of screen is displaying some information. Is there way to remove the picture without clearing the whole screen? say for example I have one picture 200 X 480 and a 2nd picture 600 X 480 is it possible to remove just the 2nd picture? Or is the only way to do a cls and load the 1st picture again? (which I'd rather avoid if possible) |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10223 |
use the BOX command |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I thought of that but wasn't sure if it would work with the picture still there. I presume it overwrites the picture as if the picture had been cleared? |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Last "stupid" question for tonight I'm trying to get a 1 second tick timer so I can do things at interval x seconds [code]Sub L1 secs2 = secs2 + 1 'update seconds timer[/code] isn't working I can't use secs = secs + 1 because I'm using secs in the clock routine. If I use secs and try this if secs => 5 "then do something" will ONLY do the something at 5 seconds past every minute, not every 5 second interval |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
If people are getting sick of me asking for help, please tell me and I'll stop posting. I know I must be annoying some people. I'm stuck on this section.. I cannot figure out how to associate a box with a touch I have 2 boxes on the screen (touch switches) that when touched each one will do something different, Can anyone PLEASE help me to figure out how to make the boxes as touch (switches?) [code]BOX 255, 0, 140, 30, 2, RGB(white),RGB(brown) BOX 396, 0, 150, 30, 2, RGB(white),RGB(brown)[/code] I've had a look at several projects with touchscreens and it's just too advanced for my head to take in. Once I can configure them as touch boxes, I can work out how to associate the functions I need with the touch It's getting the touch to work in the first place I'm completely stuck with |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
In a TouchDown interrupt sub you can check for the X, and Y coordinates of the point touched. If both X and Y fall within the region of the BOX coordinates then you can take it as being touched. i.e. Taking your first box above: In TouchDown Interrupt check following: IF Touch(X)>255 AND Touch(X)<(255+140) AND Touch(Y)>0 AND Touch(Y)<(0+30) THEN 'touched first box There are other ways; but hopefully you can follow this method ![]() |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4037 |
You can do things like if secs MOD 5 = 0 then ... BTW, You'd mean >= rather than => if you were using that kind of test John |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Sometimes this will not work because IF the 'other stuff' in code is taking a long time before it reachs the IF secs MOD 5 = 0 test, then secs may have 'rolled' over to the next value and hence MOD 5 will not equal zero. I have had a scenario where it never 'hit'. My recommendation is to use another variable counter in the TICK sub, and then check >= (or =>) in the IF statement (and reset to 0 in the IF THEN when true). This way it will always 'hit' albeit possibly 'late' Hope this makes sense ![]() |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4037 |
I've never written software so slow that it came even near to failing. I suppose I don't need more than a second to do things!! But if you do, then you'd need to use something similar that allowed for the things taking so l-o-n-g despite the fast CPUs we have now. You could easily do the test in the tick timer and set a flag to say the 5 seconds were up. Then you'd have until the next 5 seconds to do whatever action it was. If you're taking more than 5 secs then you need a re-think although you're already missing the 5 second deadline anyway by that stage. (The current CPUs are 1000 or 10,000 times faster than I used in the old days when I had dozens of active tasks so someone must have horribly busy code.) John |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
@JohnS, If you use Load Image then this can make the above MOD test 'miss'. This is just one scenario - nothing to do with writing slow code (or needing to re-think it) - just that some 'actions' may take time and hence why the test won't always work. The example I gave is a working solution that I think Lewis will hopefully be able to follow. PC CPUs are extremely fast in comparison but it still takes more than a minute for Win10 to boot up - an example of horribly busy code ![]() |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4037 |
Sure, if you do anything that takes so long then you of course need to program around it. I thought we were referring to uC-type code, so Win10's many issues don't really apply - thank goodness! (I'm avoiding it, anyway, and happy with Linux.) Load Image is presumably busy waiting and doing nothing much during the wait (for I/O, well I/P in this case). I wonder if the tick interrupts even occur on time during it... If anything time-critical is needed, it may even mean that Load Image and the like simply cannot be used - very typical of real-time uC stuff in the case where you have a single-tasking system (like MMBasic) and some internal part can take too long (may be MMBasic in this example). Sometimes you can code round the limitations. John |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you so much to everyone I now have the touch working, and it's changing pages exactly like I wanted ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
How can I do this? [code]IF Touch(X)>396 AND Touch(X)<(396+150) AND Touch(Y)>0 AND Touch(Y)<(0+30) AND if secs3 > 180 THEN Page2 ELSE Page1 END IF[/code] Error: Expression syntax I want the touch to ONLY work after a period of 180 seconds has passed I tried this and it lets the touch work with no errors BUT it doesn't ignore the touch command for the first 180 seconds [code]if secs3 > 180 AND Touch(X)>396 AND Touch(X)<(396+150) AND Touch(Y)>0 AND Touch(Y)<(0+30) THEN Page2 ELSE Page1 END IF[/code] secs3 routine [quote] SETTICK 1000 , L2,2 SUB L2 secs3 = secs3 + 1 END SUB[/code] |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4037 |
You have an extra "if" among the ANDs John |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |