Older Version Newer Version

bshipps64 bshipps64 Apr 6, 2006 - "First created"

BinClock

A demo illustrating the use of graphicboxes and a bitmap to represent a binary clock.


LED bitmap: blueLED.bmp
 nomainwin 

global led$, s$, xOn, xOff

s$ = "ff n"
p$ = "h m s"

led$ = "blueLED.bmp"
ledFile$ = "bmp\" + led$
BackgroundColor$ = "black"

xOn = 0
xOff = -15
REFRESH.INTERVAL = 250

loadbmp led$, ledFile$

WindowWidth = 164
WindowHeight = 120

graphicbox #binClock.gbh10, 10, 44, 15, 34
graphicbox #binClock.gbh1, 30, 10, 15, 68
graphicbox #binClock.gbm10, 60, 27, 15, 51
graphicbox #binClock.gbm1, 80, 10, 15, 68
graphicbox #binClock.gbs10, 110, 27, 15, 51
graphicbox #binClock.gbs1, 130, 10, 15, 68

stylebits #binClock.gbh10, 0, _WS_BORDER, 0, 0
stylebits #binClock.gbh1, 0, _WS_BORDER, 0, 0
stylebits #binClock.gbm10, 0, _WS_BORDER, 0, 0
stylebits #binClock.gbm1, 0, _WS_BORDER, 0, 0
stylebits #binClock.gbs10, 0, _WS_BORDER, 0, 0
stylebits #binClock.gbs1, 0, _WS_BORDER, 0, 0
stylebits #binClock, 0, 0, _WS_EX_TOPMOST, 0

open "BinClock" for window_nf as #binClock
#binClock "trapclose [exit]"

for i = 1 to 6
ext$ = word$(p$,int((i/2) + .5)) + "1" + word$("0",(i mod 2))
hGB$ = "#binClock.gb" + ext$
#hGB$ "down; fill "; BackgroundColor$
next i

[refreshTime]
timer 0
currTime$ = time$()
if (currTime$ <> lastDisplayed$) then
for i = 3 to 1 step -1
t$ = word$(currTime$,i,":")
pT$ = word$(lastDisplayed$,i,":")
if (t$ <> pT$) then call UpdateGBPair word$(p$,i), val(t$)
next i
lastDisplayed$ = currTime$
end if

timer REFRESH.INTERVAL, [refreshTime]
wait

[exit]
close #binClock
end

sub UpdateGBPair group$, value
gbO$ = "#binClock.gb" + group$ + "1"
gbT$ = gbO$ + "0"
sO$ = upper$(group$) + "1"
sT$ = sO$ + "0"
tCount = (group$ <> "h") + 1
tens = int(value / 10)
ones = value mod 10

#gbT$ "delsegment currSegment"; sT$
#gbO$ "delsegment currSegment"; sO$

for i = tCount to 0 step -1
state$ = eval$("xO" + word$(s$, (tens and (2^i)) + 1))
yPos$ = str$(17 * j)
j = j + 1
#gbT$ "drawbmp "; led$; " "; state$; " "; yPos$
next i

j = 0
for i = 3 to 0 step -1
state$ = eval$("xO" + word$(s$, (ones and (2^i)) + 1))
yPos$ = str$(17 * j)
j = j + 1
#gbO$ "drawbmp "; led$; " "; state$; " "; yPos$
next i

#gbT$ "flush currSegment"; sT$
#gbO$ "flush currSegment"; sO$
#binClock "refresh"
end sub