-
Notifications
You must be signed in to change notification settings - Fork 0
/
musicListener.js
59 lines (43 loc) · 1.09 KB
/
musicListener.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
#!/usr/bin/env node
// Listens for messages on a queue and plays notes
var mqtt = require('mqtt')
var servo = require('./servo.js');
var servos = [];
console.log('Configuring Servos')
var i;
for (i = 1; i <= 8; i++) {
servos.push(new servo(i));
}
console.log('Connecting to Queue')
var client = mqtt.connect('ws://localhost:1884');
client.on('connect', function () {
client.subscribe('AGC_BBBL_Music/+/Commands')
})
client.on('message', function (topic, message) {
// message is Buffer
var cmd = message.toString();
if (cmd.substring(0, 4) == 'PLAY') {
var channel = cmd.substring(4, 5);
playNote(channel);
}
})
function playNote(channel) {
console.log(channel);
var servo = servos[channel - 1];
servo.moveTo(-0.5,-0.5,10);
servo.moveTo(-0.5,0.0,50);
servo.moveTo(0.0,-0.5,100);
}
process.on('SIGINT', function () {
console.log("Shutting down SIGINT (Ctrl-C)");
client.end()
process.exit();
})
function doStuff() {
console.log("Heartbeat...");
};
function run() {
console.log('Running')
setInterval(doStuff, 30000);
};
run();