rust_gpiozero

Build Status

A simple interface to GPIO devices with Raspberry Pi.

This library is based on GPIOZero library.

Note: This is a work in progress. The library will eventually support embedded-hal based drivers

The idea is to get started with physical computing using Rust with little coding by hiding the underlying complexity.

The library uses BCM Pin numbering

Example : Blinking an LED

```rust

extern crate rustgpiozero; use rustgpiozero::*;

fn main() {

// Create a new LED attached to Pin 17

let mut led = LED::new(17);

// blink the LED // ontime: 2 seconds and offtime: 3 seconds

led.blink(2,3);

}

```

Example : Wait for a Button Press

```rust extern crate rustgpiozero; use rustgpiozero::*;

fn main() { // Create a button which is attached to Pin 17 let button = Button::new(17); button.waitforpress(); println!("button pressed");

}

```

Compare this to using the crate sysfs_gpio to blink an LED on the Raspberry Pi :

```rust

extern crate sysfs_gpio;

use sysfs_gpio::{Direction, Pin}; use std::thread::sleep; use std::time::Duration;

fn main() { let myled = Pin::new(127); // number depends on chip, etc. myled.withexported(|| { loop { myled.setvalue(0).unwrap(); sleep(Duration::frommillis(200)); myled.setvalue(1).unwrap(); sleep(Duration::from_millis(200)); } }).unwrap(); }

```

Install/Use

To use rust_gpiozero, first add this to your Cargo.toml:

toml [dependencies] rust_gpiozero = "0.1.0"

Features

The following features are planned :

License

GNU General Public License v3.0