![]() |
Forum Index : Microcontroller and PC projects : Question about Touch
![]() ![]() |
|||||
Author | Message | ||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9593 |
It does. ![]() ![]() These are normal results. Yours are really badly off. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
The problem was the touchscreen Luckily I had a spare put away somewhere, found it and connected it and it works great The buzzer even beeps now when the screen it touched :) Now is there any way to "draw" 2 arrows? 1 in red and 1 in blue? Red facing up and the blue facing down but I only want one displayed at any one time? |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Can someone check this code and tell me if it "should" work please? It draws the boxes properly and Touch "SHOULD" work in the boxes but its not maybe I've made a "stupid" mistake? [code] rBOX 560 ,295,170,50,10,RGB(BLACK),RGB(131,178,37) 'displaybox "Tomorrow" rbox 560 ,355,170,50,10,RGB(BLACK),RGB(GREEN) 'displaybox "Day 2" rBOX 560 ,415,170,50,10,RGB(BLACK),RGB(BLUE) 'displaybox "Day 3" TEXT 640,320, "Tomorrow", CM, 3, 1, RGB(black),RGB(131,178,37) TEXT 640,380, "Day 2", CM, 3, 1, RGB(black),RGB(GREEN) TEXT 640,440, "Day 3", CM, 3, 1, RGB(black),RGB(BLUE) ' '***********************IF the Buttons are touched******************************** IF Touch(X)>560 AND Touch(X)<(730) AND Touch(Y)>295 AND Touch(Y)< (345) THEN print "Tomorrow Touched" 'If Touch pressed IF Touch(X)>560 AND Touch(X)<(730) AND Touch(Y)>355 AND Touch(Y)< (405) THEN print "Day 2 Touched" 'If Touch pressed IF Touch(X)>560 AND Touch(X)<(730) AND Touch(Y)>415 AND Touch(Y)< (465) THEN print "Day 3 Touched" 'If Touch pressed [/code] |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9593 |
Great you found the touchscreen was crook - something was not right there.... ![]() Why are you NOT using buttons and advanced GUI controls? IE: Why are you using touch co-ordinates instead of buttons, and basic drawing commands like TEXT instead of GUI CAPTION? GUI BUTTON will automatically configure the touch co-ordinates for you. All you have to do, is define the button with the GUI BUTTON command. As an example, take the following button: This will draw a large-ish button down the bottom of a 7" LCD, then when you touch it, it will animate as being touched, and will make the 'Click' noise from the peizo if you have set up that side of things. This will keep running, even at the command prompt, so if you type in the above at the command prompt and press ENTER(change BU_MR_ACK to a number), you should get a button on the screen, and when you touch it, it should 'Click' and look like it is depressed. Release it, and it should pop back up again. To check this button, you use the TOUCH(REF) function inside a GUI INTERRUPT, such as this: Then you catch that touch inside a loop. I will try to find a little time tonight to take YOUR example, and just re-format it with touch buttons, captions, and an interrupt so you can see the whole picture if what I am writing here still has you scratching your head. Don't worry if you ARE still scratching your head - GUI's are confusing for a start. Smoke makes things work. When the smoke gets out, it stops! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I did try GUI BUTTON but I couldn't get it to do what I wanted because I want it to jump to a sub when it is pressed but what I found is while it is pressed it kept going to that sub and nothing else until I touched the button again to release it Unless you know a way to get it to only go to the sub once :) |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9593 |
You probably need some flags to tell the system what the state of the button is. I will rustle up some demo code in the next few hours and post it here. Smoke makes things work. When the smoke gets out, it stops! |
||||
KeepIS![]() Guru ![]() Joined: 13/10/2014 Location: AustraliaPosts: 1874 |
The two code examples I posted on Page 2 take care of that. Here it is again. In this case you were using a switch, changing it to a button is correct way to go. CONST GUI_TOMORROW = 25 CONST GUI_DAY2 = 26 CONST GUI_DAY3 = 27 GUI SWITCH GUI_TOMORROW,560,295,170,50,RGB(BLACK),RGB(RED) GUI SWITCH GUI_DAY2,560,355,170,50,RGB(BLACK),RGB(GREEN) GUI SWITCH GUI_DAY3,560,415,170,50,RGB(BLACK),RGB(BLUE) Sub PenDown() Select CASE Touch(REF) CASE GUI_TOMORROW TOMORROW CASE GUI_DAY2 DAY2 CASE GUI_DAY3 DAY3 END SELECT END SUB Or do it this way in the main loop. DIM ThisControl as integer Sub PenDown() Select CASE Touch(REF) CASE GUI_TOMORROW ThisControl = 1 CASE GUI_DAY2 ThisControl = 2 CASE GUI_DAY3 ThisControl = 3 END SELECT END SUB DO IF ThisControl = 1 then TOMORROW IF ThisControl = 2 then DAY2 IF ThisControl = 3 then DAY3 ThisControl = 0 LOOP NANO Inverter: Full download - Only Hex Ver 8.1Ks |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9593 |
Completely agree with KeepIS above, so I won't bother to post any demo code. TOMORROW, DAY2 and DAY3 are your subroutine names that you want to call. Please do stick with it - GUI is confusing for a start, but hang in there, cos once you know how to do it, it is a fabulous feature to know how to use. Smoke makes things work. When the smoke gets out, it stops! |
||||
GoodToGo!![]() Senior Member ![]() Joined: 23/04/2017 Location: AustraliaPosts: 188 |
I might chime in here, Both the Grog-man and KeepIS are right, but if I may, I'll just make a couple of additions to KeepIS' code to hopefully make it easier to understand:- CONST GUI_TOMORROW = 25 CONST GUI_DAY2 = 26 CONST GUI_DAY3 = 27 GUI INTERRUPT PenDown 'Important line, without it Pendown won't be called GUI BUTTON GUI_TOMORROW,"Tomorrow",560,295,170,50,RGB(BLACK),RGB(RED) GUI BUTTON GUI_DAY2,"Day2",560,355,170,50,RGB(BLACK),RGB(GREEN) GUI BUTTON GUI_DAY3,"Day3",560,415,170,50,RGB(BLACK),RGB(BLUE) Sub PenDown Select CASE Touch(REF) CASE GUI_TOMORROW 'is the TOMORROW button pressed? TOMORROW 'call sub TOMORROW CASE GUI_DAY2 'is the DAY2 button pressed? DAY2 'call sub DAY2 CASE GUI_DAY3 'is the DAY3 button pressed? DAY3 'call sub DAY3 CASE ELSE 'the "oops I didn't expect this" case EXIT SUB END SELECT END SUB Sub TOMORROW 'your code here END SUB Sub DAY2 'your code here END SUB Sub DAY3 'your code here END SUB Personally I think in this case GUI BUTTON's instead of SWITCH's are the way to go. The Button is a momentary type of control, whereas the switch is a click on/ click off job. It's definitely worth converting all of your controls to the GUI set of commands. They are a lot easier to work with. Hope the above makes sense, GTG! ![]() ...... Don't worry mate, it'll be GoodToGo! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you so much everyone ![]() I really couldn't get my head around how the gui interrupt worked and how touching the button worked thanks to everyone it's now really clear and really simple once you actually understand it |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Is there a way to delete display boxes? AN example is The main program draws display boxes in the top left quarter of the screen If I call a subroutine by touching a button Is there any way to delete those display boxes? There's a background picture so I ideally don't want to do a CLS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10251 |
MM+ manual GUI HIDE or GUI DELETE |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Peter, I do read the manuals but unfortunately I forgot things like GUI Hide after I started working out how GUI worked. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Just tried GUI HIDE and unfortunately it replaces the GUI button with a black box (current background colour) Edit: GUI DELETE does the same as GUI HIDE What I'd like to do is remove the button but leave the background picture there instead of a black box I presume this isn't possible |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |