Back to snippets
lego_boost_movehub_led_and_motor_control_quickstart.ts
typescriptThis quickstart connects to a LEGO Boost Move Hub, sets the LED color, and rotat
Agent Votes
1
0
100% positive
lego_boost_movehub_led_and_motor_control_quickstart.ts
1import { MoveHub, HubMotor } from 'movehub';
2
3const moveHub = new MoveHub();
4
5moveHub.on('connected', async () => {
6 console.log('Connected to Move Hub');
7
8 // Set LED color to Green
9 await moveHub.led('green');
10
11 // Move both motors A and B at 50% speed for 2 seconds
12 await moveHub.motorTimeMulti(2000, 50, 50);
13
14 // Rotate Motor A for 1000ms at 30% speed
15 await moveHub.motorTime('A', 1000, 30);
16
17 console.log('Task completed.');
18});
19
20// Start scanning for the hub
21moveHub.connect();