# IoT Case 09: Smart Digital Morning Clock Level:  
## Goal
## Background
Smart digital clock is a clock that shows time as accurate as to atomic clock by connecting to the Internet.
Smart Digital Clock Principle
NTP protocol ensures devices synchronize their time with an accurate time internet provider. With connecting to the Internet, the digital clock can show the time close to atomic clock in millisecond .
In the program, it will get the internet time every 0.5 second to show the time on the OLED. When the time is arrived to specific time (e.g. 06:00:00), it will turn on the alert. Otherwise, it will turn of the buzzer. When the user pressed the button A, the alarm can be closed. 
## Part List
## Assembly step
In this case, build the “Big Style Model” as a home base.

Step 2
Let’s build a bed room to install a digital clock. Put the model E3 onto cardboard A, align with the holes at model A and B3.

Step 3
Attach the OLED display as a digital clock to the model E3 using M2 \* 10mm screws and nuts.

Step 4
Put the model E4 onto cardboard A, align with the holes at model A and B4.

Step 5
To build a bed. Put model J2 onto the model J1, then put together all the cardboard parts (J1-J3).

Step 6
The bed completed!

Step 7
Place the bed next to the digital clock at the room.

Step 8
Assembly Completed!

## Hardware connect
## Programming (MakeCode)
Step 2. Check Wi-Fi connection state
* Snap the `On WiFi connected` block to editor * Put a `show icon tick` inside the block to show tick icon after connected 
Step 3. Get the NTP time
* Put a `if` statement in `Forever` * Use `WiFi connected?` as condition * In `if` segment, put `Get NTP Current Time at city HongKong(UTC+8)` to get NTP time * `Pause 500ms` to get the NTP time with each 0.5 second 
Step 4. Show the NTP time on display
* Put `On NTP received` to editor * When get the NTP time, the program in this block will running * Clear the display before each update by `Clear OLED display` * Show the formatted time string with `show string join Date: day.Month.Year` * Show the formatted time string with `show string join Time: Hour:Minute:Second` 
Step 5. Set the alarm
* Put a `if` statement with multiple conditions `Hour = 6` and `Minute = 0` and `Second = 6` * Put `set alarmTrig to true` in `if` segment 
Step 6. Set up the sound
* Put another `Forever` to editor * Put a `if-else` statement inside the `Forever` * Use `alarmTrig = true` as condition * Play the alarm by melody at tempo 500 bpm * Otherwise, stop the alarm 
Step 7. Turn off alarm
* Put `on Button A pressed` to editor * Put `set alarmTrig to false` into the block 
Full Solution
MakeCode: [https://makecode.microbit.org/S77738-06496-37751-47481](https://makecode.microbit.org/S77738-06496-37751-47481)
You could also download the program from the following website:

## Think
## Result
After you connected to the Internet, the tick will open an start getting NTP time.
Q1. Apart from showing the time and alarm, any other tasks can be done when we know the time?