Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:09 04 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 : Analog Clock (Sample Code)[MMBasic]

Author Message
Yourock17
Newbie

Joined: 09/01/2015
Location: Australia
Posts: 12
Posted: 12:22am 05 Jun 2015
Copy link to clipboard 
Print this post

Hello, I have made an analog clock that features:
-A Wake-Up Alarm, That doesn't sound on weekends :D
-Second, Minute and Hour hands.
-AM/PM Support

Made For
Monochrome Maximite
Firmware Ver: 3.0203
Horizontal Res: 480
Vertical Res: 432


SetPin 1,8
Print "0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thur, 5=Fri, 6=Sat"
Input "Enter The Day Using The Above Code (D): ", D
Input "Enter The Alarm Time: ", Alarm$
Input "Enter The Time: ", T$
Time$ = T$
Cls
Font 1,2
DRAWFACE
Do
Seconds = Val(Right$(Time$, 2))
Minutes = Val(Mid$(Time$, 4,2))
Hours = Val(Left$(Time$, 2))
If Hours > 12 Then
PM$ = "Yes"
Else
PM$ = "No"
EndIf
If Time$ = "00:00:00" Then
D = D+1
D = D Mod 7
EndIf
If Time$ = Alarm$ Then ALARM
Hours = Hours*5+(Minutes/12)
Minutes = Minutes+(Seconds/60)
''''''''
'Second Hand
''''''''
SDegrees = (60-(Seconds+30))*0.10467
XS = 240+200*Sin(SDegrees)
YS = 210+200*Cos(SDegrees)
''''''''
'Minute Hand
''''''''
MDegrees = (60-(Minutes+30))*0.10467
XM = 240+180*Sin(MDegrees)
YM = 210+180*Cos(MDegrees)
''''''''
'Hour Hand
''''''''
HDegrees = (60-(Hours+30))*0.10467
XH = 240+100*Sin(HDegrees)
YH = 210+100*Cos(HDegrees)
''''''''''''''''''
'Drawing The Hands
''''''''''''''''''
Cls
DRAWFACE
Print@(240,240) "PM:" PM$
Line(240,210)-(XS,YS),1
Line(240,210)-(XM,YM),1
Line(240,210)-(XH,YH),1
Pause 1000
Loop
''''''''''
'Drawing The Face
''''''''''
Sub DRAWFACE
Num = 0
Do
Num = Num+1
Digit = Num Mod 5
FaceDeg = (60-(Num+30))*0.10467
OX = 240+210*Sin(FaceDeg)
OY = 210+210*Cos(FaceDeg)
IX = 240+205*Sin(FaceDeg)
IY = 210+205*Cos(FaceDeg)
Line(IX,IY)-(OX,OY),1
If Digit = 0 Then Print@((OX-15),(OY-5)) (Num/5)
Loop Until Num > 59
End Sub
''''''''''
'Alarm
''''''''''
Sub ALARM
If D = 0 Or D = 6 Then GoTo 3
Cls
Decider = Fix(Rnd*4)
If Decider = 0 Then Print@(200,200) "Time To Get Up"
If Decider = 1 Then Print@(200,200) "Wake Up Sweetie"
If Decider = 2 Then Print@(200,200) "Mornin' Sunshine"
If Decider = 3 Then Print@(200,200) "Just Get Up"
If Decider = 4 Then Print@(200,200) "Helllooooo"
If Decider = 5 Then Print@(200,200) "Cmon, Get Up"
If Alarm$ = "07:00:00" Then Print@(200,200) "Its Just School :( "
If Hour < 7 And TOD$ = "AM" Then Print@(200,200) "Its A Bit Early! "
If D = 5 Then Print@(200,200) "Whoo, Its Friday! "
Print@(100,300) "Press <Space> to stop!"
K$ = ""
Do
Pin(1)=1
Pause 200
Pin(1)=0
Pause 100
Pin(1)=1
Pause 200
Pin(1)=0
Pause 500
K$ = UCase$(Inkey$)
Looped = Looped + 1
TimeRem = 180-Looped
Min = Fix(TimeRem/60)
Sec = TimeRem Mod 60
Font 1
Print@(50,350) "Or Alarm Will Stop In: " Min " Minutes and " Sec " Seconds"
Loop Until K$ = Chr$(32) Or Looped = 600
Cls
3 Font 2
End Sub


I am really proud of this as I have recently learnt trigonometry. Thank you. Also could anyone give hints as to how to fix the flashing :)Edited by Yourock17 2015-06-06
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:04am 05 Jun 2015
Copy link to clipboard 
Print this post

Kye
You have done well to post your versions of hardware and software. The version of MMBasic has moved on substantially since your chip was loaded. Version 4.5 is the latest. You should consider updating. You can get the latest MMBasic on this page http://geoffg.net/maximite.html and this link will take you straight to the download http://geoffg.net/Downloads/Maximite/Maximite_MMBasic.zip. You should find new firmware, support programs and manuals in that ZIP.

This program is good practice for your trig. Sorry I can't help with the flashing. You may have to give a bit more info.

Hint: put square brackets around your smiley or use the sidebar. You'll get a graphic then. Click more... under the smilies in the sidebar.
Bob
 
Yourock17
Newbie

Joined: 09/01/2015
Location: Australia
Posts: 12
Posted: 02:43am 05 Jun 2015
Copy link to clipboard 
Print this post

Thanks Bob for the tips, I have never attempted updating and probably should. I also forgot to mention in the post that there is a Piezo Buzzer attacted to Pin 1. Damn it does it's job with the Buzzer.
 
mbramwel

Regular Member

Joined: 10/07/2013
Location: Canada
Posts: 42
Posted: 10:06am 05 Jun 2015
Copy link to clipboard 
Print this post

I do not have a maximite setup to test this.

Some comments based on reading the code:

You are clearing the screen and then rewriting the entire screen contents.
Consider not doing this.

Instead, perhaps you should clear just where where the text is written and write new text on the screen.

For the hands, write the old hands first with the color set to the background color, this causes them to disappear.
Then write the new hands using the foreground color.
This means only the hands are rewritten and the flashing would not be noticeable.

In practice it means you have a first-run routine that draws any text boxes and related non-changing screen items.
You would have a screen refresh routine that runs once a second that updates the screen by erasing text, write new text; erase hands, write new hands.

 
Print this page


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

© JAQ Software 2024