First: the needed lib (bi, bas -- source(s)), are found in Forum --> Projects.
SevenSegmentClock.bas:
Code: Select all
' SevenSegmentClock.bas -- 2017-08-19, by MrSwiss
'
' compile: -s gui
#Include "SevenSegment.bi"
' decimal splitter macro (range: 0 to 99), tens/units
#Define T_U(num) ( CUShort(((num \ 10) Shl 8) + num Mod 10) )
' init code: clock specific positioning (spaces in between HR/MIN/SEC)
Dim As SevenSeg SS(5) ' 6 elements SevenSeg (0 to 5)
Dim As UShort startx, starty, endx, endy, sp_sec, sp_min, sp_hou
For i As UInteger = 0 To 5
SS(i).initSS() ' sizes SevenSeg (default = 6)
SS(i).clr_SS(b_red, d_red, black, blue) ' bright/dark LED, bg, frame
Select Case As Const i ' positioning depending on prev. set position
Case 0 : SS(i).pos_SS(30, 30) ' first position only
Case 1, 3, 5 : SS(i).pos_SS(endx + 1, 30) ' to position, border
Case 2, 4 : SS(i).pos_SS(endx + 21, 30) ' pos. + space = 20
End Select
SS(i).gframe( ,, endx) ' get end pos. x-axis (+1 = next start pos.)
If i = 0 Then SS(i).gframe(startx, starty) ' store start pos. SS(0)
If i = 5 Then SS(i).gframe( ,,, endy) ' on SS(5), endpos. y-axis
Next ' we now have start/end coordinates of the whole SevenSeg block!
' seconds in a different color (than hours/minutes)
SS(4).clr_SS(b_blu, d_blu) : SS(5).clr_SS(b_blu, d_blu)
' done (init)
' ===== MAIN =====
' using obtained sizes (from init), to size the screen (no need to know them!)
ScreenRes(endx + startx, endy + starty, 32, 2, &h60) ' Alpha Primitives + allways on top
ScreenSet(1, 0)
WindowTitle "SevenSegmentClock -- " + _ ' display (hpefully) useful info's
"width: " + Str(endx + startx) + " " + _
"height: " + Str(endy + starty)
Color(white, &hFF003F00) : Cls ' custom green (background)
Dim As String cTime = Time, TM = "MrSwiss made(TM)", _
title = "Digital 24 hour's clock, using SevenSegment-Library"
Do
If Time <> cTime Then ' run's once a second only, (> fails: on date change!)
Cls
cTime = Time ' update time (below: use of the defined macro!)
sp_hou = T_U(CUByte(Left(cTime, 2))) ' split: tens digit, units digit
sp_min = T_U(CUByte(Mid(cTime, 4, 2))) ' as above (minutes)
sp_sec = T_U(CUByte(Right(cTime, 2))) ' as above (seconds)
If HiByte(sp_hou) = 0 Then ' switch OFF, leading zero (on Hour's, only)
SS(0).dec_SS(16) ' all segments OFF (on a SevenSeg)
Else
SS(0).dec_SS(HiByte(sp_hou)) ' decode it (LED's: ON/OFF status)
End If : SS(0).dis_SS() ' show it, no frame: default
SS(1).dec_SS(LoByte(sp_hou)) : SS(1).dis_SS() ' decode digit : display digit
SS(2).dec_SS(HiByte(sp_min)) : SS(2).dis_SS() ' as above ...
SS(3).dec_SS(LoByte(sp_min)) : SS(3).dis_SS()
SS(4).dec_SS(HiByte(sp_sec)) : SS(4).dis_SS()
SS(5).dec_SS(LoByte(sp_sec)) : SS(5).dis_SS()
Draw String ( 23, 12), title ' using default foreground color
Draw String (165,135), TM, &hFFFFCF00 ' custom yellow
Flip
End If
If Len(InKey()) Then Exit Do ' check for user input
Sleep(100, 1) ' wait for 100 mS (no user interrupt)
Loop
' ===== END-MAIN ===== ' ----- EOF -----
#Include "SevenSegment.bi" with: #Include "SevenSegment[nn].bas"
(nn = either 32 or 64), place the included .bas next to SevenSegmentClock.bas,
then compile SevenSegmentClock.bas only ...