Digital Clock
MagicBlocks Project

Digital Clock

A Digital Clock on Magicbit Display

What is a Digital Clock?

A digital clock is a type of clock that displays the time digitally.

Magicblocks is easy visual programming software for the program of your Magicbit. Anyone can program their microcontroller by using magicblocks.io and there is no need for programming knowledge. You can sign up for free.

Add Inject, Function & Display blocks to the playground

Connect them as follows,

Double click on the inject node and set repeat to every 1 second.

Double click on the function node. Copy and paste the code as shown in the photo.

// Get the current time and convert it to text
var now = new Date();

let localDate = new Date(now.toLocaleString('en-US', { timeZone: "Asia/Colombo" }));

var hh = now.getHours();
var mmm = now.getMinutes();
var ss = now.getSeconds();

msg.payload = hh +":"+mmm+":"+ss;

return msg;

Double click on the Display node and select the correct Device Id and set the font size to 2.

Deploy the program and you will see the clock on the display.

Related Posts
Leave a Reply