• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
3* Copyright (c) 2015 Intel Corporation.
4*
5* Permission is hereby granted, free of charge, to any person obtaining
6* a copy of this software and associated documentation files (the
7* "Software"), to deal in the Software without restriction, including
8* without limitation the rights to use, copy, modify, merge, publish,
9* distribute, sublicense, and/or sell copies of the Software, and to
10* permit persons to whom the Software is furnished to do so, subject to
11* the following conditions:
12*
13* The above copyright notice and this permission notice shall be
14* included in all copies or substantial portions of the Software.
15*
16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*/
24
25// Some vars
26var colon = true;
27var interval;
28
29// Load display
30var tm1637 = require('jsupm_tm1637');
31
32// Instantiate on pins 0 (Clk) and 1 (Dio)
33var display = new tm1637.TM1637(0, 1);
34
35// Get the current time
36var now = new Date();
37console.log("System time: " + now.getHours() + ":" + ("0" + now.getMinutes()).slice(-2));
38console.log("Time zone can be changed by setting the TZ environment variable.");
39
40// Display and time update function
41function update(){
42    now = new Date();
43    var time = now.getHours().toString() + ("0" + now.getMinutes().toString()).slice(-2);
44    display.writeString(time);
45    display.setColon(colon = !colon);
46}
47
48// Start with a 7-segment encoded box on the display
49display.write(0x39, 0x09, 0x09, 0x0f);
50
51// Start displaying the clock after 3 seconds
52setTimeout(function(){
53    // And update every second thereafter
54    interval = setInterval(update, 1000);
55}, 3000)
56
57// Exit handler
58process.on('SIGINT', function()
59{
60    clearInterval(interval);
61    display = null;
62    tm1637.cleanUp();
63    tm1637 = null;
64    console.log("Interrupt received, exiting...");
65    process.exit(0);
66});
67