In Depth Banner
Skip Navigation Links

Select your preferred language

The LED Clock Timer Handler

The handler routine updates the flashing colon by determining if the current second is less than half-way through, then the hours are adjusted for 12 and 24 hour format. Finally, the hours and minutes are converted to a string and the resulting characters used to update the LEDControls that display the numerals.

    private void timer1_Tick(object sender, System.EventArgs e)

    {

      DateTime dt=DateTime.Now;

      if((dt.TimeOfDay.TotalSeconds-(float)Math.Floor(dt.TimeOfDay.TotalSeconds))>0.5)

        this.ledControl3.DisplayChar=':';

      else

        this.ledControl3.DisplayChar=' ';

 

 

      int hour=dt.TimeOfDay.Hours;

      if(hour>12 && !TwentyFourHour)

        hour-=12;

      if(hour==0 && !TwentyFourHour)

        hour+=12;

      string h=hour.ToString("00");

      string m=dt.TimeOfDay.Minutes.ToString("00");

 

      this.ledControl1.DisplayChar=h[0];

      this.ledControl2.DisplayChar=h[1];

      this.ledControl4.DisplayChar=m[0];

      this.ledControl5.DisplayChar=m[1];

 

    }

 

Return to the article

Copyright © Bob Powell 2003-2009. All rights reserved