Skip to content

Commit b668295

Browse files
committed
added example
1 parent 44366d0 commit b668295

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed

examples/.gitignore

Whitespace-only changes.

examples/binary-clock.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env node
2+
3+
/*
4+
* Copyright (C) 2017 Alasdair Mercer, !ninja
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
var blinkt = require('../src/blinkt');
28+
29+
blinkt.setClearOnExit();
30+
31+
var MODE_HOUR = 0;
32+
var MODE_MIN = 1;
33+
var MODE_SEC = 2;
34+
35+
var mode = 0;
36+
var timeInMode = 0;
37+
var timeToStayInMode = 3;
38+
39+
var lh = 0;
40+
var lm = 0;
41+
42+
setInterval(function() {
43+
var t = new Date();
44+
var h = t.getHours();
45+
var m = t.getMinutes();
46+
var s = t.getSeconds();
47+
var b, bit, g, r;
48+
49+
console.log([ h, m, s, mode, timeInMode ]);
50+
51+
if (h !== lh) {
52+
mode = MODE_HOUR;
53+
timeInMode = 0;
54+
} else if (m !== lm) {
55+
mode = MODE_MIN;
56+
timeInMode = 0;
57+
}
58+
59+
lm = m;
60+
lh = h;
61+
62+
blinkt.clear();
63+
64+
if ((s % 2) === 0) {
65+
blinkt.setPixel(1, 64, 64, 64);
66+
}
67+
68+
if (mode === MODE_HOUR) {
69+
blinkt.setPixel(0, 255, 0, 0);
70+
71+
for (i = 0; i < 6; i++) {
72+
bit = (h & (1 << x)) > 0;
73+
r = 128 * bit;
74+
g = 128 * bit;
75+
b = 128 * bit;
76+
77+
blinkt.setPixel(7 - i, r, g, b);
78+
}
79+
}
80+
81+
if (mode === MODE_MIN) {
82+
blinkt.setPixel(0, 0, 255, 0);
83+
84+
for (i = 0; i < 6; i++) {
85+
bit = (m & (1 << x)) > 0;
86+
r = 128 * bit;
87+
g = 128 * bit;
88+
b = 128 * bit;
89+
90+
blinkt.setPixel(7 - i, r, g, b);
91+
}
92+
}
93+
94+
if (mode === MODE_SEC) {
95+
blinkt.setPixel(0, 0, 0, 255);
96+
97+
for (i = 0; i < 6; i++) {
98+
bit = (s & (1 << x)) > 0;
99+
r = 128 * bit;
100+
g = 128 * bit;
101+
b = 128 * bit;
102+
103+
blinkt.setPixel(7 - i, r, g, b);
104+
}
105+
}
106+
107+
blinkt.show();
108+
109+
timeInMode += 1;
110+
111+
if (timeInMode === timeToStayInMode) {
112+
mode += 1;
113+
mode %= 3;
114+
timeInMode = 0;
115+
}
116+
}, 1000);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blinkt",
3-
"version": "0.1.0",
3+
"version": "0.0.1",
44
"description": "Module for interacting with the Raspberry Pi Blinkt! addon",
55
"homepage": "https://github.com/NotNinja/node-blinkt",
66
"bugs": {

0 commit comments

Comments
 (0)