From 539d4f7995b53361c4aec3160eb175150eec2e1a Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Sat, 2 Jan 2016 14:41:42 -0800 Subject: [PATCH] Updating Rust to be functional --- resources/rust/main.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/resources/rust/main.rs b/resources/rust/main.rs index 3e66076f..16cfe2f2 100644 --- a/resources/rust/main.rs +++ b/resources/rust/main.rs @@ -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(); - } -} \ No newline at end of file + // 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)); + } +}