-
Notifications
You must be signed in to change notification settings - Fork 15
/
demiurge.js
executable file
·53 lines (44 loc) · 1.08 KB
/
demiurge.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
var powerMotorLeft = brick.motor(M1);
var powerMotorRight = brick.motor(M2);
var scriptLines =
"#put all script lines here\n"
+ "sleep 20\n"
var scriptToKill = "autorun." + new Date().getTime() + ".sh"
var scriptFileName = "/tmp/" + scriptToKill
script.writeToFile(scriptFileName, scriptLines);
script.system("chmod +x " + scriptFileName)
gamepad.pad.connect(
function(padId, x, y) {
powerMotorLeft.setPower(y+x);
powerMotorRight.setPower(y-x);
}
)
gamepad.padUp.connect(
function(padId, x, y) {
powerMotorLeft.powerOff();
powerMotorRight.powerOff();
}
)
gamepad.button.connect(
function(buttonId, pressed) {
switch (buttonId) {
case 1: {
var command = "killall -9 -q " + scriptToKill;
script.system(command);
brick.led().orange();
break;
}
case 2: {
var command = scriptFileName
+ " && echo 1 > /sys/class/leds/led_red/brightness"
+ " && echo 1 > /sys/class/leds/led_green/brightness";
brick.led().green();
script.system(command);
break;
}
default: break;
}
}
)
brick.led().orange();
script.run();