A really simple, and basic digital clock. Primary purpose is for Windows 10 IoT installed on Raspberry Pi 3 running on official pi display.
I built this with Visual Studio 2019 Community Edition.
After deployment, login to your pi3 iot on your pi3lanipaddress:8080, and you can set the application to run at startup.
Microsoft Guide for Setting up a Raspberry Pi
For Pi, deploy to ARM target, Remote Device.
When you select Remote Machine from the dropdown, Visual Studio will detect your Pi3 assuming it's online connected to your LAN.
It takes very little code to get this clock running.
- Add the visual text block to the MainPage.xaml, named it txtTime.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="txtTime" Grid.Row = "0" Grid.Column = "0" Text="Initializing Time"
IsTextSelectionEnabled="False" TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="140" />
</Grid>
- Create the ticker to serve as the clock's engine, and fire it up in MainPage.xaml.cs
public MainPage()
{
this.InitializeComponent();
DispatcherTimer Timer = new DispatcherTimer();
Timer.Tick += Timer_Tick;
Timer.Interval = new TimeSpan(0, 0, 1); // hh,mi,ss tick once per second
Timer.Start(); // kick off the ticker forever
}
async void Timer_Tick(object Sender, object e)
{
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
// Run the Code
txtTime.Text = DateTime.Now.ToString("hh:mm:ss tt"); // update the xaml text object with friendy string formatted time
});
}