Skip to content

Commit

Permalink
added example
Browse files Browse the repository at this point in the history
  • Loading branch information
neocotic committed Jun 21, 2017
1 parent 44366d0 commit b668295
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
Empty file removed examples/.gitignore
Empty file.
116 changes: 116 additions & 0 deletions examples/binary-clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env node

/*
* Copyright (C) 2017 Alasdair Mercer, !ninja
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

'use strict';

var blinkt = require('../src/blinkt');

blinkt.setClearOnExit();

var MODE_HOUR = 0;
var MODE_MIN = 1;
var MODE_SEC = 2;

var mode = 0;
var timeInMode = 0;
var timeToStayInMode = 3;

var lh = 0;
var lm = 0;

setInterval(function() {
var t = new Date();
var h = t.getHours();
var m = t.getMinutes();
var s = t.getSeconds();
var b, bit, g, r;

console.log([ h, m, s, mode, timeInMode ]);

if (h !== lh) {
mode = MODE_HOUR;
timeInMode = 0;
} else if (m !== lm) {
mode = MODE_MIN;
timeInMode = 0;
}

lm = m;
lh = h;

blinkt.clear();

if ((s % 2) === 0) {
blinkt.setPixel(1, 64, 64, 64);
}

if (mode === MODE_HOUR) {
blinkt.setPixel(0, 255, 0, 0);

for (i = 0; i < 6; i++) {
bit = (h & (1 << x)) > 0;
r = 128 * bit;
g = 128 * bit;
b = 128 * bit;

blinkt.setPixel(7 - i, r, g, b);
}
}

if (mode === MODE_MIN) {
blinkt.setPixel(0, 0, 255, 0);

for (i = 0; i < 6; i++) {
bit = (m & (1 << x)) > 0;
r = 128 * bit;
g = 128 * bit;
b = 128 * bit;

blinkt.setPixel(7 - i, r, g, b);
}
}

if (mode === MODE_SEC) {
blinkt.setPixel(0, 0, 0, 255);

for (i = 0; i < 6; i++) {
bit = (s & (1 << x)) > 0;
r = 128 * bit;
g = 128 * bit;
b = 128 * bit;

blinkt.setPixel(7 - i, r, g, b);
}
}

blinkt.show();

timeInMode += 1;

if (timeInMode === timeToStayInMode) {
mode += 1;
mode %= 3;
timeInMode = 0;
}
}, 1000);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blinkt",
"version": "0.1.0",
"version": "0.0.1",
"description": "Module for interacting with the Raspberry Pi Blinkt! addon",
"homepage": "https://github.com/NotNinja/node-blinkt",
"bugs": {
Expand Down

0 comments on commit b668295

Please sign in to comment.