From b6b53c4dbcaf8f0914f2abf833d5a4170a7bc0fe Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 21 Dec 2019 17:22:50 -0500 Subject: [PATCH] Start second light display --- harrogate/Cargo.toml | 1 + harrogate/src/december_21_2019.rs | 61 +++++++++++++++++++++++++++++++ harrogate/src/main.rs | 4 ++ 3 files changed, 66 insertions(+) create mode 100644 harrogate/src/december_21_2019.rs diff --git a/harrogate/Cargo.toml b/harrogate/Cargo.toml index 90fcca3..998c9b7 100644 --- a/harrogate/Cargo.toml +++ b/harrogate/Cargo.toml @@ -14,6 +14,7 @@ debug = true replace-default = [] december-01-2019 = ["replace-default"] +december-21-2019 = ["replace-default"] [dependencies] house = { path = "../house" } diff --git a/harrogate/src/december_21_2019.rs b/harrogate/src/december_21_2019.rs new file mode 100644 index 0000000..29dbd64 --- /dev/null +++ b/harrogate/src/december_21_2019.rs @@ -0,0 +1,61 @@ +//! Golden background with twinkling lights +use super::delay; +use house::Harrogate; +use lights::rgb::Rgb; +use lights::{HardwareRgb, Lights, murmurf}; + +const GOLD: Rgb = Rgb(200, 200, 0); +const RED: Rgb = Rgb(0, 200, 0); +const GREEN: Rgb = Rgb(0, 200, 0); +const BLUE: Rgb = Rgb(0, 0, 200); +const PURPLE: Rgb = Rgb(160, 0, 128); +const WHITE: Rgb = Rgb(255, 255, 255); + +const FULL_PORCH: usize = 150; + +#[derive(Copy, Clone)] +struct Pixel { + color: Rgb, +} + +impl Pixel { + const fn new() -> Pixel { + Pixel { + color: GOLD + } + } + + fn tick(&mut self, mut rng: u32) { + self.color = match murmurf(&mut rng) % 8 { + 0..=1 => RED, + 2..=3 => GREEN, + 4..=5 => BLUE, + 6 => PURPLE, + 7 => WHITE, + _ => GOLD, + } + } +} + +#[allow(dead_code)] +#[inline(always)] +pub fn run(lights: &mut impl Lights) -> ! { + + let mut rng = 1; + let mut pixels = [Pixel::new(); FULL_PORCH]; + + for pixel in pixels.iter_mut() { + pixel.tick(murmurf(&mut rng)); + } + + loop { + + Harrogate { + porch_back: (0..FULL_PORCH).map(|_| GOLD), + porch_front: pixels.iter().map(|p| p.color) + } + .render_to(lights); + + delay(300_000); + } +} diff --git a/harrogate/src/main.rs b/harrogate/src/main.rs index 958447a..967ea15 100644 --- a/harrogate/src/main.rs +++ b/harrogate/src/main.rs @@ -6,6 +6,7 @@ use lights_hal::{boot, entry}; pub use lights_hal::delay; mod december_01_2019; +mod december_21_2019; mod door_light; #[entry] @@ -15,6 +16,9 @@ fn main() -> ! { #[cfg(feature = "december-01-2019")] december_01_2019::run(&mut lights); + #[cfg(feature = "december-21-2019")] + december_21_2019::run(&mut lights); + #[cfg(not(feature = "replace-default"))] door_light::run(&mut lights); }