-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (29 loc) · 815 Bytes
/
index.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
var PythonShell = require('python-shell');
var myVar = setInterval(function(){
startColor({
x: random(0, 7),
y: random(0, 7),
r: random(0, 255),
g: random(0, 255),
b: random(0, 255)
});
}, 500);
function random(min, max) {
return Math.floor(Math.random() * max) + min;
}
function startColor(color) {
var pyshell = new PythonShell('SenseHat.py');
console.log(color);
pyshell.send( JSON.stringify(color) );
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log("--python--");
console.log(message);
});
pyshell.end(function (err,code,signal) {
if (err) throw err;
//console.log('The exit code was: ' + code);
//console.log('The exit signal was: ' + signal);
console.log('finished');
});
}