Clock: digital clock

266 views
Skip to first unread message

Scott Ferguson

unread,
May 25, 2014, 9:22:46 PM5/25/14
to
About: The clock component allows all sorts of things to happen based on a timer. Blocks placed inside a clock's Timer event block will be executed over and over based on the delay setting of the Clock.

This example uses some clock component blocks and the Screen component to make a digital clock.

Create a new project named lrn_clk_digclk

Screen Designer:

Change the Screen1 Title to <time displays here> .















Drag out a Clock component onto the center of the Viewer layout window.
 - it will jump to the bottom of the Viewer panel below Non-Visible components.
 - note the Clock1 Property TimerInterval is 1000. This is 1 second in milliseconds.
 - we don't need to change this as we want our clock display to change every 1 second.
















Blocks Editor:

Drag out a Clock1.Timer event block.
 - this block will execute any blocks inside it every 1 second based on its TimerInterval of 1000.







Drag out a Screen1.Title block and drop it inside the Clock1.Timer block.
 - this block will display the date and time on the app's title bar.
























Drag out a Clock1.FormatDateTime block and attach it to the Screen1.Title block.


Drag out a Clock1.Now block and attach it to the Clock1.FormatDateTime block.


Test your project.
If it is working, you should see current date and time displayed on your emulator or attached device and it will update every second.
If the emulator date/time is wrong, the emulator's clock is just not set but the project is still working correctly.
The output should be similar to this:







END.

Challenge:

Try substituting some of the other Clock1 call blocks for Clock1.FormatDateTime. 
lrn_clk_digclk.zip
Reply all
Reply to author
Forward
0 new messages