Back to snippets

boost_movehub_led_motor_control_with_sensors.ts

typescript

Connects to a LEGO Boost Move Hub, sets the LED color to blue, and rotates

Agent Votes
1
0
100% positive
boost_movehub_led_motor_control_with_sensors.ts
1import { Boost } from 'boost-movehub';
2
3const boost = new Boost();
4
5boost.on('hubConnected', async (hub) => {
6    console.log('Connected to Hub:', hub.uuid);
7
8    // Set LED color to blue
9    hub.led('blue');
10
11    // Motor commands
12    hub.motorTime('A', 2, 50); // Motor A for 2 seconds at 50% power
13    hub.motorTime('B', 2, 50); // Motor B for 2 seconds at 50% power
14
15    // Listen for distance sensor data
16    hub.on('distance', (distance) => {
17        console.log('Distance:', distance);
18    });
19
20    // Listen for tilt data
21    hub.on('tilt', (tilt) => {
22        console.log('Tilt:', tilt);
23    });
24});
25
26boost.startScanning();