A simple interface to GPIO devices with Raspberry Pi.
This library is based on GPIOZero library.
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
```rust
use rust_gpiozero::*;
fn main() { // Create a new LED attached to Pin 17 let mut led = LED::new(17); // blink the LED led.blink(2.0, 3.0); }
```
```rust
use rust_gpiozero::*;
fn main() { // Create a button which is attached to Pin 17 let mut button = Button::new(17); button.waitforpress(None); 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(); }
```
To use rust_gpiozero
, first add this to your Cargo.toml:
toml
[dependencies]
rust_gpiozero = "0.2.0"
Compiling your project on a Raspberry Pi directly can take significant time depending on the model. Ideally, you would cross compile your project then run it on the Raspberry Pi.
The following features are planned :
embedded-hal
GNU General Public License v3.0
This library would not be possible without the great work of the maintainers of GPIOZero and rppal
Thanks for your interest in rust_gpiozero
. I am a newbie rustacean and just started using the language! I am using this project to learn more about Rust. Feel free to give feedback or send PRs. Your experiences and feedback will also benefit others who use this library.