Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:28 15 May 2024 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 : MM+ End Sub

     Page 1 of 2    
Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 08:20pm 18 Aug 2015
Copy link to clipboard 
Print this post

I have some code that works perfectly well with the 170 chip, but when I loaded it into the MM+ I have a problem. This is part of the code:-

SetTick 200, POSITION, 1
'
'
'
'
'
sub POSITION
If Touch(x) >215 And Touch(x) < 255 Then
Latitude$ = Left$(arg$(3) ,2)+" "+Mid$(arg$(3) ,3)+" "+arg$(4)
Longitude$ = Left$(arg$(5) ,3)+" "+Mid$(arg$(5) ,4)+" "+arg$(6)
CLS(Yellow)
Text 150,100,"CURRENT POSITION",CM,2,2,RGB(Cyan)
Text 145, 140, "Lat " + Latitude$,CM,2,2,RGB(Cyan)
Text 145, 180, "Lon " + Longitude$,CM,2,2,RGB(Cyan)
Flags= 0
Pause 10000
GoSub Display
ELSE END SUB
endif
GoTo START

When working, if the screen is touched it branches to this SUB and displays the current position for 10 secs. before returning to the SUB DISPLAY which displays the normal screen.

The problem is the settick goes to the Sub POSITION, the screen is not touched so TOUCH(X) and TOUCH(y) are both -1 (checked this)
but the ELSE END SUB is not processed and the program goes to START.

This code has been working perfectly with the 170 chip for many months.

Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 08:51pm 18 Aug 2015
Copy link to clipboard 
Print this post

Paul
2 things and I can't test either. Instead of END SUB it should probably be EXIT SUB and it may need to be on the line following the ELSE.

The rules may be tighter with different firmware.
Bob
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 09:03pm 18 Aug 2015
Copy link to clipboard 
Print this post

Paul,

BobD is correct in that the ELSE has to be on its own line with the 'else statement' also on its own line.
See Page 52 of Manual (v4.7) which shows syntax for single line and multi-line IF statements.

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 09:29pm 18 Aug 2015
Copy link to clipboard 
Print this post

I'm running 4.7 on the 170s but it may be different in this version. Will try later.
Thanks for the replies, will get back.
Paul.

Edit.
Just altered the code and it works fine. Thanks again.
Paul.Edited by palcal 2015-08-20
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:41pm 18 Aug 2015
Copy link to clipboard 
Print this post

Paul,

With subroutines you need to make sure that it has a start and an end.
Otherwise the interpreter will loose track of where it is.
A subroutine starts with the word SUB followed by the name.
[code]
SUB mySubroutine
[/code]
after this line you can write the code that has to be executed when the subroutine is called.
after the code you need to 'close' the subroutine with
[code]
END SUB
[/code]
This will cause the interpreter to go back to were it was when the subroutine was called.
You can not jump out of a subroutine with a GOTO. The interpreter will then not see an END SUB and will think that it is still inside the subroutine. This should trigger an error but interpreters are normally not so strict. Eventually the program wil run out of memory because each time it executes a subroutine it has to remember were to go back to.
If you need to get out of a subroutine use EXIT SUB.
Also it is best to not use any pause in subroutines that are used with timers or interrupts.

You can also consider using then new GUI commands to capture a touch.
[code]
Micromite Plus only.
In addition, on the Micromite Plus an interrupt
can be triggered on touch down and up.
The following command will set up the interrupt:

GUI INTERRUPT down [, up]

Where 'down' is the subroutine to call when a touch down
has been detected. And optionally 'up' is the subroutine
to call when the touch has been lifted from the screen
('up' and 'down' can point to the same subroutine if required).
Specifying the number zero (single digit) as the argument
will cancel both of these interrupts. ie:

GUI INTERRUPT 0
[/code]


Edited by TZAdvantage 2015-08-20
Microblocks. Build with logic.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 09:55pm 18 Aug 2015
Copy link to clipboard 
Print this post

Thanks, I changed the code when I switched from push buttons to touch. With the push buttons I used the interrupt to set a flag and then return to the main code so it didn't spend long in the interrupt. I forgot about using PAUSE in an interrupt not being good practice. I will try the GUI INTERRUPT command or maybe go back to using the SUB to just set a flag.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 10:08pm 18 Aug 2015
Copy link to clipboard 
Print this post

With TOUCH, is is a good idea to store the X Y values quickly then do you tests. The touch(X) will be constantly changing and that can make life interesting when you are trying to do tests.
SUB tapped
LOCAL tx,ty
tx=TOUCH(X)
ty=TOUCH(Y)
IF ty < 120 AND ty >0 THEN
etc...


Be prepared for some -1 values as the finger leaves the screen.

JimEdited by TassyJim 2015-08-20
VK7JH
MMedit   MMBasic Help
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 11:08pm 18 Aug 2015
Copy link to clipboard 
Print this post

When using the GUI INTERRUPT command, can I have more than one interrupt.
I tried it and only one interrupt works. Reading the manual I don't think I can.
Paul.Edited by palcal 2015-08-20
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 08:37am 19 Aug 2015
Copy link to clipboard 
Print this post

  palcal said   When using the GUI INTERRUPT command, can I have more than one interrupt.

You can have two interrupts. One for touch down and another for touch up.

Within the interrupt use a SELECT CASE statement or some other way to determine what is being touched. See page 23 of the advanced manual.

Geoff
Geoff Graham - http://geoffg.net
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 11:48am 19 Aug 2015
Copy link to clipboard 
Print this post

Thanks Geoff, was reading all that last night. I just have to get my little brain to understand it all, but I'm confident I will have it up and running soon.
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 02:51pm 19 Aug 2015
Copy link to clipboard 
Print this post

Trying to test my new code but MM+ wont connect to my GPS receiver. I am using the command 'OPEN "COM2:4800" As #1' but I see in the advanced Manual that the OPEN command is used to OPEN a file for reading or writing. Is there any conflict here.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 03:10pm 19 Aug 2015
Copy link to clipboard 
Print this post

It should work for either COM ports or files and your command looks OK to me.

Jim
VK7JH
MMedit   MMBasic Help
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9075
Posted: 03:17pm 19 Aug 2015
Copy link to clipboard 
Print this post

I have done a bit of playing around with serial on the new MM+, and can confirm that the serial ports do work, so this command should be working for you.

What is the rest of the code you are using to talk to the GPS on COM2?

It is quite possible that there is an error there, as COM2 to the GPS device should actually be open.

At the command prompt, and assuming that some data should have been sent by the GPS module, type the following:

? LOC(#1)

If the number is zero, no data has been received. If the number is not zero, then there is data from the GPS sitting in COM2's receive buffer waiting for you. Edited by Grogster 2015-08-21
Smoke makes things work. When the smoke gets out, it stops!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 03:25pm 19 Aug 2015
Copy link to clipboard 
Print this post

The rest of the code is OK I have it working on other devices. Just wanted to confirm the OPEN command before I looked elsewhere.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 06:55pm 19 Aug 2015
Copy link to clipboard 
Print this post

OK Iv'e been working on this for most of the day. I just can't get the COMM port to work on the Explore-64 board. I checked the TX connection from the GPS back to pin 59 on the 470 (I'm using COMM1) and it is OK. I have printed out what I am receiving and the characters are rubbish. If I connect the GPS to the board running a 170 chip with exactly the same code it works fine.
I'm stumped and need a break maybe alcohol is the answer.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5923
Posted: 08:13pm 19 Aug 2015
Copy link to clipboard 
Print this post

Rubbish characters are usually a wrong baud rate or inverted signal.

Try adding 'INV' to the end of your comspecs. You will need a few of the optional parameters in there as well.

Jim
VK7JH
MMedit   MMBasic Help
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 08:22pm 19 Aug 2015
Copy link to clipboard 
Print this post

  Quote  Try adding 'INV' to the end of your comspecs


I doubt that could be the problem as it all works on the 170 chip.
Is there a way to test the COMM PORT by tying TX and RX together.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 07:23pm 22 Aug 2015
Copy link to clipboard 
Print this post

OK after many hours I have this working in a sort of fashion, but still have a problem with 'TOUCH'
When a button is touched I want to go to another screen so I had to use GUI DELETE to get rid of the buttons but when I return to the main screen and redraw the GUI BUTTONS they don't work.
Try this short example


GUI INTERRUPT CHOOSE

START:
Screen

Do
Loop

Sub Screen
GUI BUTTON #1, "SELECT",50,100,185,40,RGB(Black),RGB(Green)
End Sub

CHOOSE:
GUI Delete #1
CLS
Pause 2000
GoTo Start


After the interrupt the screen is redrawn but the button won't work.

Paul.

Edit: I tried GUI HIDE and GUI RESTORE with the same result.Edited by palcal 2015-08-24
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:53pm 22 Aug 2015
Copy link to clipboard 
Print this post

Can not test it here but rewrite your code like this:

[code]
ActiveScreen = 0
NextScreen = 1
GUI INTERRUPT CHOOSE

Do
if NextScreen <> ActiveScreen then
Screen NextScreen
endif
Loop

Sub Screen(value)
if value = 1 then
GUI BUTTON #1, "SELECT",50,100,185,40,RGB(Black),RGB(Green)
endif
if value = 2 then
GUI DELETE #1
CLS
pause 2000
NextScreen = 1
endif
ActiveScreen = value
End Sub

Sub CHOOSE
'You can add code here to examine the touch location and decide which screen
'you want to show.
NextScreen = 2
End Sub

[/code]
Edited by TZAdvantage 2015-08-24
Microblocks. Build with logic.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1805
Posted: 08:45pm 22 Aug 2015
Copy link to clipboard 
Print this post

Thanks TZ but your code won't work for me. When you a next near an MM+ can you test and advise.
Paul.Edited by palcal 2015-08-24
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
     Page 1 of 2    
Print this page
© JAQ Software 2024