-
Notifications
You must be signed in to change notification settings - Fork 0
/
compass.js
115 lines (105 loc) · 3.3 KB
/
compass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//console.log(qiblah.bearing);
var five = require("johnny-five"),
fsr, led;
pixel = require("node-pixel");
var qiblah = require("./qiblah");
var Omx = require('node-omxplayer');
var board = new five.Board();
var fps = 15;
// Touchpad Sensor
/*
});*/
board.on("ready", function() {
var fsr = new five.Sensor({
pin: "A0",
freq: 1000
});
var light = new pixel.Strip({
board: this,
controller: "FIRMATA",
strips: [ {pin: 5, length: 6}, {pin: 6, length: 16}, {pin: 7, length: 6}, ], // this is preferred form for definition
gamma: 2.8, // set to a gamma that works nicely for WS2812
});
/**** START UP ****/
console.log("RING");
var colors = ["rgb(0,50,0)"];
var current_colors = [0];
var current_pos = [6];
var executed = 0;
var blinker = setInterval(function() {
light.color("#000"); // blanks it out
for (var i=0; i < current_pos.length; i++) {
if (++current_pos[i] >= 22) {
current_pos[i] = 6;
executed++;
if (++current_colors[i] >= colors.length) current_colors[i] = 0;
}
if (executed < 5) {
var end = light.pixel(current_pos[i]).color(colors[current_colors[i]]);
light.show();
}
}
}, 1000/fps);
fsr.scale([0, 255]).on("data", function() {
if (this.scaled > 130) {
var compass = new five.Compass({
controller: "HMC5883L"
});
compass.on("change", function() {
console.log(Math.floor(this.heading));
//QIBLAH
if (Math.floor(this.heading) < (qiblah.bearing + 5) && Math.floor(this.heading) > (qiblah.bearing - 5)) {
console.log("qiblah: " + Math.floor(this.heading));
light.color("rgb(0, 50, 0)");
light.show();
//var player = Omx("sounds/adhan.wav", 0);
}
//GO RIGHT
else if (Math.floor(this.heading) < 360 && Math.floor(this.heading) > 199) {
console.log("GO RIGHT");
for (var i = 0; i < 22; i++) {
var ringLeft = light.pixel(i).color("rgb(50,50,50)");
}
for (var i = 22; i < 28; i++) {
light.pixel(i).color("rgb(50, 0, 0)");
}
light.show();
}
else if (Math.floor(this.heading) < (qiblah.bearing - 5)) {
console.log("GO RIGHT");
for (var i = 0; i < 22; i++) {
var ringLeft = light.pixel(i).color("rgb(50,50,50)");
}
for (var i = 22; i < 28; i++) {
light.pixel(i).color("rgb(50, 0, 0)");
}
light.show();
}
//GO LEFT
else if (Math.floor(this.heading) < 199) {
console.log("GO RIGHT");
for (var i = 6; i < 28; i++) {
var ringLeft = light.pixel(i).color("rgb(50,50,50)");
}
for (var i = 0; i < 6; i++) {
light.pixel(i).color("rgb(50, 0, 0)");
}
light.show();
}
else if (Math.floor(this.heading) > (qiblah.bearing + 5)) {
console.log("GO RIGHT");
for (var i = 6; i < 28; i++) {
var ringLeft = light.pixel(i).color("rgb(50,50,50)");
}
for (var i = 0; i < 6; i++) {
light.pixel(i).color("rgb(50, 0, 0)");
}
light.show();
}
});
}
else {
console.log(this.scaled);
}
});
});