forked from kaspesla/ev3_scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ev3_example_test.js
55 lines (37 loc) · 1.12 KB
/
ev3_example_test.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
const ev3 = require('./ev3');
// change me
const deviceName = '/dev/tty.EV3-SerialPort';
async function delay(ms) {
await new Promise(r => setTimeout(r, ms));
}
async function driveLoop(brick) {
while(true) {
await brick.startMotors("A+D", 10);
await delay(5000);
await brick.halt();
await delay(5000);
await brick.startMotors("A+D", -10);
await delay(5000);
await brick.halt();
await delay(5000);
await brick.steerMotors("A+D", "left", 1);
await delay(5000);
await brick.steerMotors("A+D", "right", 1);
await delay(5000);
}
}
async function sensorLoop(brick) {
while(true){
console.log('touch', await brick.readTouchSensor('1'));
console.log('gyro angle', await brick.readGyroGensor( '2', 'angle'));
console.log('color', await brick.readColorSensor('3', 'color'));
console.log('distance', await brick.readDistanceSensor('4'));
await delay(1400);
}
}
async function main() {
let brick = await ev3({deviceName});
driveLoop(brick);
sensorLoop(brick);
}
main();