GithubHelp home page GithubHelp logo

joakim000 / lego-powered-up Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bricks-rs/lego-powered-up

0.0 0.0 0.0 982 KB

Control the Lego PF2/Powered-Up devices over BLE from Rust

License: Mozilla Public License 2.0

Rust 100.00%

lego-powered-up's Introduction

Rust communication library for Lego Powered Up

Example

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(())
}

Contributing

Contributions are welcome, particularly in the following areas:

  • Bug reports and feature requests
  • Support for hubs other than the Technic Medium Hub (I don't have any other types to test with at the moment)
  • Support for peripherals other than the simple motors and hub LEDs
  • Good APIs to control e.g. motor position
  • More examples to demonstrate cool things we can do
  • Client implementation
  • #![no_std] support (controller & client)
  • Testing on/porting to non-linux operating systems, e.g. Windows & Mac

License

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

lego-powered-up's People

Contributors

sciguy16 avatar dependabot[bot] avatar romw314 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.