Jump to content

Binary Clock


SpookMeister
 Share

Recommended Posts

Why? Well... why not?

; BinClock
#include <GUIconstants.au3>

#region - Make GUI
GUICreate("BinClock", 135, 115)

$T_Hour2 = GUICtrlCreateLabel("0", 10, 60, 15, 15)
$T_Hour1 = GUICtrlCreateLabel("0", 10, 80, 15, 15)
$Hour8 = GUICtrlCreateLabel("0", 30, 20, 15, 15)
$Hour4 = GUICtrlCreateLabel("0", 30, 40, 15, 15)
$Hour2 = GUICtrlCreateLabel("0", 30, 60, 15, 15)
$Hour1 = GUICtrlCreateLabel("0", 30, 80, 15, 15)
$T_Min4 = GUICtrlCreateLabel("0", 50, 40, 15, 15)
$T_Min2 = GUICtrlCreateLabel("0", 50, 60, 15, 15)
$T_Min1 = GUICtrlCreateLabel("0", 50, 80, 15, 15)
$Min8 = GUICtrlCreateLabel("0", 70, 20, 15, 15)
$Min4 = GUICtrlCreateLabel("0", 70, 40, 15, 15)
$Min2 = GUICtrlCreateLabel("0", 70, 60, 15, 15)
$Min1 = GUICtrlCreateLabel("0", 70, 80, 15, 15)
$T_Sec4 = GUICtrlCreateLabel("0", 90, 40, 15, 15)
$T_Sec2 = GUICtrlCreateLabel("0", 90, 60, 15, 15)
$T_Sec1 = GUICtrlCreateLabel("0", 90, 80, 15, 15)
$Sec8 = GUICtrlCreateLabel("0", 110, 20, 15, 15)
$Sec4 = GUICtrlCreateLabel("0", 110, 40, 15, 15)
$Sec2 = GUICtrlCreateLabel("0", 110, 60, 15, 15)
$Sec1 = GUICtrlCreateLabel("0", 110, 80, 15, 15)

GUISetState()

#endregion
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Sleep(300); gives the CPU a breather
    update()
    
WEnd

#region - Functions
Func update()
; this function refreshes the time
    $strBinTime = BinTime()
    GUICtrlSetData($T_Hour2, StringMid($strBinTime, 3, 1))
    GUICtrlSetData($T_Hour1, StringMid($strBinTime, 4, 1))
    GUICtrlSetData($Hour8, StringMid($strBinTime, 5, 1))
    GUICtrlSetData($Hour4, StringMid($strBinTime, 6, 1))
    GUICtrlSetData($Hour2, StringMid($strBinTime, 7, 1))
    GUICtrlSetData($Hour1, StringMid($strBinTime, 8, 1))
    GUICtrlSetData($T_Min4, StringMid($strBinTime, 10, 1))
    GUICtrlSetData($T_Min2, StringMid($strBinTime, 11, 1))
    GUICtrlSetData($T_Min1, StringMid($strBinTime, 12, 1))
    GUICtrlSetData($Min8, StringMid($strBinTime, 13, 1))
    GUICtrlSetData($Min4, StringMid($strBinTime, 14, 1))
    GUICtrlSetData($Min2, StringMid($strBinTime, 15, 1))
    GUICtrlSetData($Min1, StringMid($strBinTime, 16, 1))
    GUICtrlSetData($T_Sec4, StringMid($strBinTime, 18, 1))
    GUICtrlSetData($T_Sec2, StringMid($strBinTime, 19, 1))
    GUICtrlSetData($T_Sec1, StringMid($strBinTime, 20, 1))
    GUICtrlSetData($Sec8, StringMid($strBinTime, 21, 1))
    GUICtrlSetData($Sec4, StringMid($strBinTime, 22, 1))
    GUICtrlSetData($Sec2, StringMid($strBinTime, 23, 1))
    GUICtrlSetData($Sec1, StringMid($strBinTime, 24, 1))
EndFunc  ;==>update

Func BinTime()
; This function makes a 24char string showing the current time in binary
    $strTime = @HOUR & @MIN & @SEC
    $xyz = ""
    For $x = 1 To 6
        $xyz = $xyz & MiniBin(StringMid($strTime, $x, 1))
    Next
    Return $xyz
EndFunc  ;==>BinTime

Func MiniBin($var)
; This function converts a single digit decimal number into a 4 char binary string
    $bin = ""
    If ($var - 8) >= 0 Then
        $var = $var - 8
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 4) >= 0 Then
        $var = $var - 4
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 2) >= 0 Then
        $var = $var - 2
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    If ($var - 1) >= 0 Then
        $var = $var - 1
        $bin = $bin & "1"
    Else
        $bin = $bin & "0"
    EndIf
    
    Return $bin
    
EndFunc  ;==>MiniBin

#endregion

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...