diff --git a/hello_gradient/src/bin/halloween2019.rs b/hello_gradient/src/bin/halloween2019.rs index ad08957..63827b3 100644 --- a/hello_gradient/src/bin/halloween2019.rs +++ b/hello_gradient/src/bin/halloween2019.rs @@ -10,12 +10,12 @@ use lights::{ Rgb } }; -use lights_hal::{boot, delay, entry, OutputPin}; +use lights_hal::{boot, delay, entry}; #[entry] fn main() -> ! { let mut lights = boot(); - lights.red_led.set_high().unwrap(); + lights.heartbeat(); let pattern = repeat(&Rgb(255,0,255)).take(150) @@ -24,15 +24,9 @@ fn main() -> ! { ).cycle(); let mut buffer = [HardwareRgb(255,255,0); 200]; - let mut light = false; loop { // blink light to demonstrate loop is still running - if light { - lights.red_led.set_high().unwrap(); - } else { - lights.red_led.set_low().unwrap(); - } - light = !light; + lights.heartbeat(); for (i, pixel) in pattern.clone().take(200).enumerate() { buffer[i] = correct(pixel); diff --git a/hello_gradient/src/bin/july4.rs b/hello_gradient/src/bin/july4.rs index f7af1f9..16b3543 100644 --- a/hello_gradient/src/bin/july4.rs +++ b/hello_gradient/src/bin/july4.rs @@ -10,12 +10,12 @@ use lights::{ Rgb } }; -use lights_hal::{boot, delay, entry, OutputPin}; +use lights_hal::{boot, delay, entry}; #[entry] fn main() -> ! { let mut lights = boot(); - lights.red_led.set_high().unwrap(); + lights.heartbeat(); let mut pattern = repeat(&Rgb(255,0,0)).take(5) @@ -34,15 +34,9 @@ fn main() -> ! { ).cycle(); let mut buffer = [HardwareRgb(255,255,0); 200]; - let mut light = false; //delay(48_000_000 * 3); loop { - if light { - lights.red_led.set_high().unwrap(); - } else { - lights.red_led.set_low().unwrap(); - } - light = !light; + lights.heartbeat(); for (i, pixel) in pattern.clone().take(200).enumerate() { buffer[i] = correct(pixel); diff --git a/itsybitsy_m0_lights/src/lib.rs b/itsybitsy_m0_lights/src/lib.rs index aa3062a..9cd4099 100644 --- a/itsybitsy_m0_lights/src/lib.rs +++ b/itsybitsy_m0_lights/src/lib.rs @@ -37,6 +37,7 @@ pub fn boot() -> NeopixelLights, impl OutputPin { pub out: T, pub high_out: U, - pub red_led: V + pub red_led: V, + pub debug_light: bool } impl NeopixelLights @@ -88,6 +90,16 @@ where self.write(byte & 0x02 != 0); self.write(byte & 0x01 != 0); } + + /// Blink light, probably to indicate a loop is still running + pub fn heartbeat(&mut self) { + if self.debug_light { + self.red_led.set_low().unwrap(); + } else { + self.red_led.set_high().unwrap(); + } + self.debug_light = !self.debug_light; + } } impl Lights for NeopixelLights