User Tools

Site Tools


k20:k20.3:k20.3.1:start

20.3.1 Timer projects 1

The examples presented are taken from self-developed and tested demonstration programmes from different chapters. Only the source code sections are given, with which the implementation of the above concept becomes visible. You will find the archives for the complete project in the download area.

Digital

20.3.1.1 Example 1 - Digital clock

Figure 20.3.1.1: Digital clock

Source code:

Private bTrennzeichen As Boolean
 
Public Sub Form_Open()
  FMain.Center
  FMain.Text = "Tempus fugit ..."
  ...
  LCDTimer.Delay = 1000 '-- oder 500 (blinkender Doppelpunkt)
  LCDTimer.Start
  LCDTimer.Trigger
End
 
Public Sub LCDTimer_Timer()
  bTrennzeichen = Not bTrennzeichen
  LCDLabel.Padding = 8
  LCDLabel.Text = Format(Now, "hh" & If(bTrennzeichen, ":", "") & "nn" & If(bTrennzeichen, ":", "") & "ss")
End

20.3.1.2 Example 2 - Analogue clock

Analog

Figure 20.3.1.2.1: Analogue clock

Source code:

Public Sub Form_Open()
  FMain.Center
  FMain.Resizable = False
  ZeitLabel.Text = "Local-Time"
 
  Timer1.Delay = 1000 ' 1000 Millisekunden = 1 Sekunde
  Timer1.Start '-- Alternative syntax: Timer1.Enabled = TRUE
 
End
 
Public Sub Timer1_Timer() ' Taktgeber im Sekundentakt
  Dim sArcus, sArcus_S, sArcus_M, sArcus_H, x, y As Single
  Dim iRadius, iCount As Integer
 
  iRadius = 88
  sArcus_S = (90 - 6 * Second(Now)) * Pi / 180
  sArcus_M = (90 - 6 * Minute(Now)) * Pi / 180
  sArcus_H = (90 - 30 * Hour(Now) - 0.5 * Minute(Now)) * Pi / 180
 
  ZeitLabel.Text = Format$(Now, "hh:nn:ss")
 
  Draw.Begin(dwTest) '-- Achtung: Ab GB 3.4 sollte `Paint` an Stelle von `Draw` verwendet werden
    Draw.Translate(dwTest.W / 2, dwTest.H / 2) ' Erst verschieben und dann skalieren!
    Draw.Scale(1, -1)
    Draw.Picture(Picture["Images/ziffernblatt.png"], -105, -105, 210, 210)
'-- Sekundenzeiger
    x = iRadius * Cos(sArcus_S)
    y = iRadius * Sin(sArcus_S)
    Draw.Foreground = Color.Red
    Draw.Line(0, 0, x, y)
'-- Minutenzeiger
    x = iRadius * Cos(sArcus_M)
    y = iRadius * Sin(sArcus_M)
    Draw.Foreground = Color.Green
    Draw.Line(0, 0, x, y)
'-- Stundenzeiger
    x = iRadius * Cos(sArcus_H)
    y = iRadius * Sin(sArcus_H)
    Draw.Foreground = Color.Blue
    Draw.LineWidth = 2
    Draw.Line(0, 0, x, y)
  Draw.End()
 
End

20.3.1.3 Example 3 - Clock with binary display

Admittedly - the display is a bit unfamiliar; but has its charm when, after some practice, you can immediately grasp and announce the time of 14:09:24:

Binär

Figure 20.3.1.3.1: Binary display of the time

Source code

Public pBitPanel[24] As Panel
 
Public Sub Form_Open()
  Dim s As Integer
  Dim z As Integer
  Dim i As Integer
  ...
  For z = 1 To 4 ' 4 Zeilen
      For s = 1 To 6 ' 6 Spalten
          i = s + 6 * z - 7
          pBitPanel[i] = New Panel(Me) As "PDigit"
          pBitPanel[i].Background = &HE2E2E2
          pBitPanel[i].Move(16 + 62 * (s - 1), 16 + 62 * (z - 1), 52, 52)
      Next
  Next
 
  Timer1.Delay = 1000
  Timer1.Start()
  Timer1.Trigger()
 
End
 
Public Sub Timer1_Timer()
  DisplayTime(SetTimeMatrix()) '-- Umfärben der 24 Panele
End
...

20.3.1.4 Example 4 - Stopwatch

This stopwatch is designed to provide convenient end and split times for specific sequences. In addition to the start and stop buttons, there is also a pause button (the display is not updated) and a continue button that switches the display back on.

Stopp-Uhr

Figure 20.3.1.4.1: Stop clock

Source code:

' Gambas class file
 
Private bTimeOut As Boolean = False
Private bPause As Boolean = False
Private iSekunden As Integer = 0
Private iMinuten As Integer = 0
 
Public Sub Form_Open()
  FMain.Center()
  FMain.Resizable = False
  TimerDP.Delay = 500
  TimerStoppUhr.Delay = 1000 '-- Test: TimerStoppUhr.Delay = 1 oder 10
  FMain.Text = "Stop-Uhr: 0 " & String.Chr(&2266) & " Zeit " & String.Chr(&2266) & " 1 Stunde"
  SetModus(True, False, False, False)
  lcdAnzeigeSekunden.Value = 0
  lcdAnzeigeMinuten.Value = 0
End
 
Public Sub btnStart_Click()
  TimerStoppUhr.Start
  TimerDP.Start
  iSekunden = 0
  iMinuten = 0
  lcdAnzeigeSekunden.Value = 0
  lcdAnzeigeMinuten.Value = 0
  SetModus(False, True, False, True)
  FMain.Text = "Stop-Uhr: 0 " & String.Chr(&2266) & " Zeit " & String.Chr(&2266) & " 1 Stunde"
End
 
Public Sub btnPause_Click()
  bPause = True
  SetModus(False, False, True, True)
End
 
Public Sub btnWeiter_Click()
  bPause = False
  SetModus(False, True, False, True)
  lcdAnzeigeSekunden.Value = iSekunden
  lcdAnzeigeMinuten.Value = iMinuten
End
 
Public Sub btnStop_Click()
  TimerStoppUhr.Stop
  TimerDP.Stop
  SetModus(True, False, False, False)
  labelDoppelpunkt.Visible = True
  bPause = False
  lcdAnzeigeSekunden.Value = iSekunden
  lcdAnzeigeMinuten.Value = iMinuten
End
 
Public Sub TimerDP_Timer()
  labelDoppelpunkt.Visible = Not labelDoppelpunkt.Visible
End
 
Public Sub TimerStoppUhr_Timer()
  If bPause = False Then
     Inc iSekunden
     lcdAnzeigeSekunden.Value = iSekunden
     If (iSekunden = 60) Then
        iSekunden = 0
        lcdAnzeigeSekunden.Value = 0
        Inc iMinuten
        lcdAnzeigeMinuten.Value = iMinuten
     Endif
  Else
     Inc iSekunden
     If (iSekunden = 60) Then
        iSekunden = 0
        Inc iMinuten
     Endif
  Endif
 
  If (iSekunden = 59) And (iMinuten = 59) Then
     bTimeOut = True
  Endif
 
  If bTimeOut = True Then
     btnStop_Click()
     lcdAnzeigeMinuten.Value = 60
     lcdAnzeigeSekunden.Value = 0
     FMain.Text = "Eine Stunde ist erreicht ..."
     bTimeOut = False
  Endif
 
End
 
Public Sub SetModus(iStart As Boolean, iPause As Boolean, iWeiter As Boolean, iStopp As Boolean)
     btnStart.Enabled = iStart
     btnPause.Enabled = iPause
     btnWeiter.Enabled = iWeiter
     btnStop.Enabled = iStopp
End
 
Public Sub Form_Close()
  If TimerStoppUhr.Enabled Then TimerStoppUhr.Stop()
  If TimerDP.Enabled Then TimerDP.Stop()
End

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k20/k20.3/k20.3.1/start.txt · Last modified: 21.10.2023 by emma

Page Tools