Christmas Countdown Timer W/ An Lcd Display, Rtc And Meadow
About the project
Use Meadow. Foundation to quickly and easily wire up a LCD screen and a RTC module to make a Christmas countdown display.
Project info
Difficulty: Easy
Platforms: Microsoft, Meadow, Wilderness Labs
Estimated time: 1 hour
License: Apache License 2.0 (Apache-2.0)
Items used in this project
Hardware components
Story
In this project we're going to build a Christmas countdown display using a 20x4 LCD display and a RTC module connected to a Meadow F7 Micro. Most of the components needed to build this project is included in the Wilderness Labs Meadow F7 w/Hack Kit Pro.
The main objective of this project is to get familiar on how to wire up a display to Meadow, and see how easy is the API to display strings on an specific line, clear the screen, and more. Also we'll learn how to use a DS1307 Real Time Clock (RTC) module, so your clock will always be on time regardless if the project is running or not. The logic is using Meadow.Foundation to build the logic with ease.
Meadow.Foundation platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, it's completely open source and maintained by the Wilderness Labs community.
If you're new working with Meadow, I suggest you go to the Getting Started w/ Meadow by Controlling the Onboard RGB LED project to properly set up your development environment.
Step 1 - Assemble the circuitFor this project, wire up your breadboard and Meadow as shown in the Fritzing diagram:
Christmas Countdown Circuit
Christmas Countdown Circuit
Step 2 - Create a Meadow Application projectCreate a new Meadow Application project in Visual Studio 2019 for Windows or macOS and name it ChristmasCountdown.
Step 3 - Add the required NuGet packagesWindows
Right-click on the ChristmasCountdown project and click Manage NuGet Packages and install the following packages to our project:
Adding CharacterDisplay and DS1307 NuGet packages
Adding CharacterDisplay and DS1307 NuGet packages
macOS
Alt-click on the ChristmasCountdown project in the Solution Explorer, and click Add => Add Nuget Package to open the NuGet Package window. Search for the following packages and add them to the project:
Adding CharacterDisplay and DS1307 NuGet packages
Adding CharacterDisplay and DS1307 NuGet packages
Step 4 - Write the code for ChristmasCountdownIn the MeadowApp main class, copy the following code below:
using System;using System.Threading;using Meadow;using Meadow.Devices;using Meadow.Foundation.Displays.Lcd;using Meadow.Foundation.RTCs;namespace ChristmasCountdown{ public class MeadowApp : App<F7Micro, AnalogReadApp> { DS1307 rtc; DateTime currentDate; CharacterDisplay display; public MeadowApp() { rtc = new DS1307(Device.CreateI2cBus()); // Uncomment only when setting the time // rtc.SetTime(new DateTime(2019, 11, 23, 20, 19, 20)); display = new CharacterDisplay ( device: Device, pinRS: Device.Pins.D15, pinE: Device.Pins.D14, pinD4: Device.Pins.D13, pinD5: Device.Pins.D12, pinD6: Device.Pins.D11, pinD7: Device.Pins.D10 ); StartCountdown(); } void StartCountdown() { currentDate = rtc.GetTime(); display.WriteLine("Current Date:", 0); display.WriteLine(rtc.GetTime().Month + "/" + rtc.GetTime().Day + "/" + rtc.GetTime().Year, 1); display.WriteLine("Christmas Countdown:", 2); while (true) { UpdateCountdown(); Thread.Sleep(60000); } } void UpdateCountdown() { var date = rtc.GetTime(); var christmasDate = new DateTime(date.Year, 12, 25); if (currentDate.Day != date.Day) { currentDate = date; display.WriteLine(currentDate.Month + "/" + currentDate.Day + "/" + currentDate.Year, 1); } var countdown = christmasDate.Subtract(date); display.WriteLine(countdown.Days + "d" + countdown.Hours + "h" + countdown.Minutes + "m to go!", 3); } }}
In the MeadowApp's constructor, we first create a DS3231 object (rtc
) and we immediately set the current date and time. We only need to set the date and time once, since the RTC module will remain having the right time. Next we instanciate a CharacterDisplay object (display
)
Lastly, in the StartCountdown()
method, we use the WriteLine(string text, int lineNumber)
method on the display to show strings on the screen, and in the infinite while loop, we subtract the current date with Christmas eve date to get the remaining time, and we call UpdateCountdown()
method to format the remaining time and update the 4th line of the screen.
Click the Run button in Visual Studio. It should look like to the following GIF:
ChristmasCountdown project running
ChristmasCountdown project running
Check out Meadow.Foundation!This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Meadow.Foundation.
- It comes with a huge peripheral driver library with drivers for the most common sensors and peripherals.
- The peripheral drivers encapsulate the core logic and expose a simple, clean, modern API.
- This project is backed by a growing community that is constantly working on building cool connected things and are always excited to help new-comers and discuss new projects.
Leave your feedback...