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.

You will need the following nodes.

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 digital clock on the display.

Related Posts
Leave a Reply