Crates.io | lego-powered-up |
lib.rs | lego-powered-up |
version | 0.4.0 |
source | src |
created_at | 2021-12-05 22:08:26.204005 |
updated_at | 2024-01-07 20:09:08.625302 |
description | Control Lego PoweredUp hubs and devices |
homepage | |
repository | https://github.com/bricks-rs/lego-powered-up |
max_upload_size | |
id | 492879 |
size | 225,446 |
See the examples directory for more!
use lego_powered_up::{notifications::Power, PoweredUp};
use std::time::Duration;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
println!("Listening for hubs...");
let mut pu = PoweredUp::init().await?;
let hub = pu.wait_for_hub().await?;
println!("Connecting to hub `{}`", hub.name);
let hub = pu.create_hub(&hub).await?;
println!("Change the hub LED to green");
let mut hub_led = hub.port(lego_powered_up::hubs::Port::HubLed).await?;
hub_led.set_rgb(&[0, 0xff, 0]).await?;
println!("Run motors");
let mut motor_c = hub.port(lego_powered_up::hubs::Port::C).await?;
let mut motor_d = hub.port(lego_powered_up::hubs::Port::D).await?;
motor_c.start_speed(50, Power::Cw(50)).await?;
motor_d.start_speed(50, Power::Cw(50)).await?;
tokio::time::sleep(Duration::from_secs(3)).await;
println!("Stop motors");
motor_c.start_speed(0, Power::Float).await?;
motor_d.start_speed(0, Power::Brake).await?;
println!("Disconnect from hub `{}`", hub.name().await?);
hub.disconnect().await?;
println!("Done!");
Ok(())
}
Contributions are welcome, particularly in the following areas:
#![no_std]
support (controller & client)This library is available under the terms of the Mozilla Public License 2.0.
The examples provided in the examples directory are dedicated to the public domain