Skip to content

Commit

Permalink
Updating Rust to be functional
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Jan 2, 2016
1 parent 44e782a commit 539d4f7
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions resources/rust/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
// Import the interface to Tessel hardware
extern crate rust_tessel as tessel;
/// A blinky example for Tessel

// Import the tessel library
extern crate rust_tessel;
// Import the Tessel API
use rust_tessel::Tessel;
// Import sleep from the standard lib
use std::thread::sleep;
// Import durations from the standard lib
use std::time::Duration;

fn main() {

// Set the led pins as outputs with initial states
let led1 = tessel.led[0].output(1);
let led2 = tessel.led[1].output(0);
// Create a new Tessel
let mut tessel = Tessel::new();

// Turn on one of the LEDs
tessel.led[2].on().unwrap();

// Toggle the led states
loop {
println!("I'm blinking! (Press CTRL + C to stop)");
led1.toggle();
led2.toggle();
}

}
// Loop forever
loop {
// Toggle each LED
tessel.led[2].toggle().unwrap();
tessel.led[3].toggle().unwrap();
// Re-execute the loop after sleeping for 100ms
sleep(Duration::from_millis(100));
}
}

0 comments on commit 539d4f7

Please sign in to comment.