From 0687f2086ace156e386452eb2e1ec0f20aa9397c Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Sun, 27 Oct 2019 01:49:03 -0400 Subject: [PATCH] Make a basic front-back color Halloween display --- hello_gradient/src/bin/halloween2019.rs | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 hello_gradient/src/bin/halloween2019.rs diff --git a/hello_gradient/src/bin/halloween2019.rs b/hello_gradient/src/bin/halloween2019.rs new file mode 100644 index 0000000..294156c --- /dev/null +++ b/hello_gradient/src/bin/halloween2019.rs @@ -0,0 +1,45 @@ +#![no_std] +#![no_main] + +use core::iter::repeat; +use lights::{ + gamma::correct, + HardwareRgb, + PixelIterator, + rgb::{ + Rgb + } +}; +use lights_hal::{boot, delay, entry, OutputPin}; + +#[entry] +fn main() -> ! { + let mut lights = boot(); + lights.red_led.set_high().unwrap(); + + let pattern = + repeat(&Rgb(255,0,128)).take(150) + .chain( + repeat(&Rgb(255,128,0)).take(150) + ).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; + + for (i, pixel) in pattern.clone().take(200).enumerate() { + buffer[i] = correct(pixel); + } + + buffer.iter().render_to(&mut lights); + + delay(12_000_000); + } +}