Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:38 17 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 : Running clock within a MMBASIC program

Author Message
nnvpaul
Newbie

Joined: 12/12/2014
Location: United States
Posts: 7
Posted: 07:19pm 12 Dec 2014
Copy link to clipboard 
Print this post

Hello
Another newbie question. Is it possible to have a running clock displayed within an MMBASIC a program? This is a Colormax2 with a clock on board. I tried.

print time$

But it will only display the time that the code was activated. It will not display a running clock. I also tried.

do
print time$
pause 1000
loop

I will get a running clock but it seems to end the possibility of any further input. I tried to make it a subroutine but it does the same thing. If I put this code at the very end of the program it would probably give me a running clock on the last screen but not any previous pages. This seems like it should be easy but I am not getting it. I could not find anything in the MMBASIC language manual or circuit gizmos beginning maximite. Any help would be greatly appreciated. BTW, thanks for turning me on to the editor. Makes it a lot easier. Thanks.
Paul
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:54pm 12 Dec 2014
Copy link to clipboard 
Print this post

Use SETTICK.
Give it an interval and the name of the subroutine and the subroutine will be run every interval.
This will work in the 'background' and will not disturb the rest of the program.
I am not giving an exact example on purpose to give you the chance to learn by reading the relevant parts of the reference manual.

One thing to be aware of is that when you print to the screen the cursor will change its position to where the next text will be printed. When you print to the screen in a subroutine you need to make sure you do any new printing from another part of the program to the right location.
Otherwise the screen will just keep on scrolling.

Have fun!

If you need further help, post what code you have so far first.

Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9078
Posted: 09:31pm 12 Dec 2014
Copy link to clipboard 
Print this post

Try this code:


dim MTH$(12) length 3
MTH$(1)="JAN":MTH$(2)="FEB":MTH$(3)="MAR":MTH$(4)="APR":MTH$ (5)="MAY":MTH$(6)="JUN"
MTH$(7)="JUL":MTH$(8)="AUG":MTH$(9)="SEP":MTH$(10)="OCT":MTH $(11)="NOV":MTH$(12)="DEC"

dim DOW$(6) length 9
DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)= "Wednesday"
DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday"

Start:
mode 4:MenuBox (Blue):Font 2
settick 250,DAT,1
Print @(10,17) + CLR$(Yellow) "H E L L O P A U L !"
Line (140,39)-(230,39),Purple:Font 1
print @(35,155) + CLR$(Red) "PRESS ANY KEY TO EXIT..."
DO:LOOP until inkey$<>""
Mode 3:Print "Do your thing, Paul!!!!"
END

DAT:
Year=val(MID$(DATE$,7,4)):Month=VAL(MID$(DATE$,4,2)):Day=val (MID$(DATE$,1,2))
print @(10,205) + clr$(Black,Blue) DOW$(DayOfWeek(Year, Month, Day)) + " " + DATE$
print @(183,205) + clr$(Black,Blue) TIME$
IReturn

SUB MenuBox (MBC)
Cls
Line (0,0)-(239,215),MBC,B:Line (1,1)-(238,214),MBC,B:Line (2,2)-(237,213),MBC,B
Line (3,3)-(236,212),MBC,B:Line (0,50)-(238,50),MBC:Line (0,51)-(238,51),MBC
for x=1 to 235 Step 5:print @(x,205) + clr$(MBC,MBC) " ":next
end SUB

function DayOfWeek(year, month, day)
a = int((14-month)/12)
m = month + 12*a - 2
y = year - a
DayOfWeek = (day + y + int(y/4)-int(y/100)+int(y/400)+int(31*m/12)) mod 7
end function


This example shows how to draw a clock and show the day of the week too. The DayOfWeek function is NOT mine - other members posted that, and I make no claim to that being my code, I just stole it for the purposes of showing the name of the day of the week.

This example shows how to use the SETTICK interrupt.
The clock interrupt is DAT. This is called every 250mS(quarter of a second), and draws the clock at the bottom of the screen. In your main code loop, you can do whatever you want to do, and the clock will keep getting updated at the bottom of the screen.

This may not suit you - it is just an example of how I am doing it in one of my applications.
Smoke makes things work. When the smoke gets out, it stops!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:24am 13 Dec 2014
Copy link to clipboard 
Print this post

@Paul,

Grogs' example is a bit complex so here's a simpler example of how SETTICK interrupts work. You can have up to four different SETTICKS running, each with their own interrupt period - see the MMBasic Manual. Each of the SETTICK commands have to point to their own subroutine.

As TZ said, the SETTICK commands run in the background, but the main program (between the dashes) is constantly looping doing whatever else you want it to do. Notice it's running pretty fast!

settick 1000,persecond,1
settick 5000,per5secs,2
timer = 0
'-----------------
main:
cls
do
print @(30,10) "Main program, looping ",timer
loop
'-----------------
sub persecond
print @(30,30) "Updating each second ",time$
end sub

sub per5secs
print @(30,50) "Updating every five seconds ",time$
end sub

Now, the code above puts things at the same place on the screen so it's nice and readable but to get a feel for what TZ meant by "scrolling off" try this. Remove the "@(30,10)" from the print command in the "main:" looping code, then RUN it. Not so pretty but you can still see those SETTICKs coming in at their correct place but very quickly disappearing because they're getting scrolled off the screen.

Stop the program with a "Ctrl C" - you may need to press it a few times.

Greg
Edited by paceman 2014-12-14
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024