Skip to content

Instantly share code, notes, and snippets.

@alevy
Last active August 17, 2017 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alevy/73d0a1e5c8784df066c86dc5da9d3107 to your computer and use it in GitHub Desktop.
Save alevy/73d0a1e5c8784df066c86dc5da9d3107 to your computer and use it in GitHub Desktop.
Rust Tock app that periodically samples the on-board sensors
#![feature(alloc)]
#![no_std]
extern crate alloc;
extern crate tock;
use alloc::fmt::Write;
use tock::console::Console;
use tock::sensors::*;
#[inline(never)]
fn main() {
let mut console = Console::new();
let mut humidity = HumiditySensor;
let mut temperature = TemperatureSensor;
let mut light = AmbientLightSensor;
let mut ninedof = unsafe { Ninedof::new() };
loop {
write!(&mut console, "Humidity: {}\n", humidity.read()).unwrap();
write!(&mut console, "Temperature: {}\n", temperature.read()).unwrap();
write!(&mut console, "Light: {}\n", light.read()).unwrap();
write!(&mut console, "Accel: {}\n", ninedof.read_acceleration()).unwrap();
tock::timer::delay_ms(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment