From b31c7beaa079af09b10939d74c59ffb1d62192f2 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 4 Jul 2020 19:56:50 -0400 Subject: [PATCH] July 4 --- harrogate/Cargo.toml | 1 + harrogate/src/july_4.rs | 42 +++++++++++++++++++++++++++++++++++++++++ harrogate/src/main.rs | 4 ++++ 3 files changed, 47 insertions(+) create mode 100644 harrogate/src/july_4.rs diff --git a/harrogate/Cargo.toml b/harrogate/Cargo.toml index 285d7be..dced8aa 100644 --- a/harrogate/Cargo.toml +++ b/harrogate/Cargo.toml @@ -19,6 +19,7 @@ december-21-2019 = ["replace-default"] december-24-2019 = ["replace-default"] valentines-2020 = ["replace-default"] st-patricks-day = ["replace-default"] +july-4 = ["replace-default"] [dependencies] house = { path = "../house" } diff --git a/harrogate/src/july_4.rs b/harrogate/src/july_4.rs new file mode 100644 index 0000000..14b9b3f --- /dev/null +++ b/harrogate/src/july_4.rs @@ -0,0 +1,42 @@ +//! 50-star USA Flag, stars on front, stripes on back. +use super::delay; +use core::iter::repeat; +use house::Harrogate; +use lights::rgb::Rgb; +use lights::{HardwareRgb, Lights}; + +const OFF: Rgb = Rgb(0, 0, 0); +const RED: Rgb = Rgb(255, 0, 0); +const WHITE: Rgb = Rgb(255, 255, 255); +const BLUE: Rgb = Rgb(0, 0, 200); + +const FULL_PORCH: usize = 150; + +#[allow(dead_code)] +#[inline(always)] +pub fn run(lights: &mut impl Lights) -> ! { + let stars = [BLUE, WHITE, BLUE] + .iter() + .cycle() + .take(FULL_PORCH) + .cloned(); + let stripes = repeat(RED) + .take(11) + .chain(repeat(WHITE).take(11)) + .cycle() + .take(11 * 12) + .chain(repeat(RED).take(11)) + .chain(repeat(OFF)) + .take(FULL_PORCH); + + let pattern = Harrogate { + porch_back: stripes, + porch_front: stars, + }; + + loop { + pattern.clone().render_to(lights); + + delay(1_000_000); + } +} diff --git a/harrogate/src/main.rs b/harrogate/src/main.rs index 056cdc4..3222703 100644 --- a/harrogate/src/main.rs +++ b/harrogate/src/main.rs @@ -10,6 +10,7 @@ mod december_21_2019; mod december_24_2019; mod valentines_2020; mod st_patricks_day; +mod july_4; mod door_light; #[entry] @@ -31,6 +32,9 @@ fn main() -> ! { #[cfg(feature = "st-patricks-day")] st_patricks_day::run(&mut lights); + #[cfg(feature = "july-4")] + july_4::run(&mut lights); + #[cfg(not(feature = "replace-default"))] door_light::run(&mut lights); }