johnny-five
Version:
The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, Raspberry Pi, Spark Core, TI Launchpad and more!
45 lines (37 loc) • 906 B
JavaScript
var moment = require("moment");
var five = require("../lib/johnny-five");
var board = new five.Board();
board.on("ready", function() {
var digits = new five.Led.Digits({
pins: {
data: 2,
cs: 3,
clock: 4,
}
});
setInterval(function() {
digits.print(time());
}, 1000);
});
function time() {
/*
The desired display looks something
like these examples:
02.25.54 P
12.30.00 A
moment.js doesn't have an option for
a single letter meridiem (nor should it,
that would be silly), so we need to
manipulate the string a bit to so that
it the string matches our desired display.
*/
return moment().format("hh.mm.ssA")
.replace(/([AP])M/, " $1");
}
// @markdown
//
// Learn More:
//
// - [JavaScript: A Digital Clock with Johnny-Five](http://bocoup.com/weblog/javascript-arduino-digital-clock-johnny-five/)
//
// @markdown