Code : Tout sélectionner
;
; 7 segments LED clock (see 7 segments LED.pb for more comments)
; F.Weil 20050329
;
Enumeration
#Window_Main
EndEnumeration
Dim LED7Code.l(31)
Procedure Digit(Number.l, Rank.l, Base.l)
Divide.l = Pow(Base, Rank)
ProcedureReturn (Number / Divide)% Base
EndProcedure
Procedure LEDSegment(x1.l, y1.l, x2.l, y2.l, Color.l)
If x2 => y2
Circle(x1, y1 + y2 / 2, y2 / 2, Color) : Circle(x1 + x2, y1 + y2 / 2, y2 / 2, Color) : Box(x1, y1, x2, y2, Color)
Else
Circle(x1 + x2 / 2, y1, x2 / 2, Color) : Circle(x1 + x2 / 2, y1 + y2, x2 / 2, Color) : Box(x1, y1, x2, y2, Color)
EndIf
EndProcedure
Procedure LED7(Digit.l, Color.l, ImageNumber.l, Width.l, Height.l)
ImageID = CreateImage(ImageNumber, Width, Height)
StartDrawing(ImageOutput())
Box(0, 0, Width, Height, $400000)
Value = LED7Code(Digit)
If Value & 1 : LEDSegment(10 * Width / 100, 0 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
If Value & 2 : LEDSegment(90 * Width / 100, 7 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
If Value & 4 : LEDSegment(90 * Width / 100, 52 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
If Value & 8 : LEDSegment(10 * Width / 100, 95 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
If Value & 16 : LEDSegment(0 * Width / 100, 52 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
If Value & 32 : LEDSegment(0 * Width / 100, 7 * Height / 100, 10 * Width / 100, 40 * Height / 100, Color) : EndIf
If Value & 64 : LEDSegment(10 * Width / 100, 48 * Height / 100, 80 * Width / 100, 5 * Height / 100, Color) : EndIf
If Value & 128 : Circle(105 * Width / 100, 185 * Height / 200, 5 * Height / 200, Color) : EndIf
StopDrawing()
ProcedureReturn ImageID
EndProcedure
Dim ImageIDs(20)
MaxRank = 18
DigitWidth = 50
DigitHeight = 100
For i = 0 To 15
Read LED7Code(i)
Next
If OpenWindow(#Window_Main, 0, 0, (DigitWidth + 2) * (MaxRank + 1), DigitHeight, 0, "")
AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
Quit = #FALSE
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Quit = #TRUE
Case #PB_Event_Menu
Select EventMenuID()
Case #PB_Shortcut_Escape
Quit = #TRUE
EndSelect
EndSelect
Now.s = FormatDate("%yyyy %mm %dd %hh %ii %ss", Date())
For i = 1 To Len(Now)
If Mid(Now, i, 1) => "0" And Mid(Now, i, 1) <= "9"
ImageIDs(i) = LED7(Digit(Val(Mid(Now, i, 1)), 0, 10), $4040FF, i, DigitWidth, DigitHeight)
Else
ImageIDs(i) = CreateImage(i, DigitWidth, DigitHeight)
EndIf
Next
ImageID = CreateImage(485, WindowWidth(), WindowHeight())
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $400000)
For i = 1 To Len(Now)
DrawImage(ImageIDs(i), (i - 1) * (DigitWidth + 2), 0)
Next
StopDrawing()
StartDrawing(WindowOutput())
DrawImage(ImageID, 0, 0)
StopDrawing()
Delay(1)
Until Quit
CloseWindow(0)
EndIf
End
DataSection
LED7CodeData:
Data.l 63, 6, 91, 79, 102, 109, 125, 7, 127, 111, 119, 124, 57, 94, 121, 113, 63, 6, 91, 79, 102, 109, 125, 7, 127, 111, 119, 124, 57, 94, 121, 113
EndDataSection