Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 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: AustraliaPosts: 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 |