#![no_std] #![no_main] #![allow(incomplete_features)] #![feature(generic_const_exprs)] use adafruit_seesaw::{devices::NeoSlider, prelude::*, SeesawRefCell}; use cortex_m_rt::entry; use rtt_target::{rprintln, rtt_init_print}; use stm32f4xx_hal::{gpio::GpioExt, i2c::I2c, pac, prelude::*, rcc::RccExt}; #[entry] fn main() -> ! { rtt_init_print!(); let cp = cortex_m::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap(); let gpiob = dp.GPIOB.split(); let clocks = dp.RCC.constrain().cfgr.freeze(); let delay = cp.SYST.delay(&clocks); let scl = gpiob.pb6.into_alternate_open_drain::<4>(); let sda = gpiob.pb7.into_alternate_open_drain::<4>(); let i2c = I2c::new(dp.I2C1, (scl, sda), 100.kHz(), &clocks); let seesaw = SeesawRefCell::new(delay, i2c); let mut neoslider = NeoSlider::new_with_default_addr(seesaw.acquire_driver()) .init() .expect("Failed to start NeoSlider"); loop { let value = neoslider.slider_value().expect("Failed to read slider"); let color = color_wheel((value / 3 & 0xFF) as u8); neoslider .set_neopixel_colors(&[color.into(), color.into(), color.into(), color.into()]) .and_then(|_| neoslider.sync_neopixel()) .expect("Failed to set neopixel colors"); } } #[panic_handler] fn handle_panic(info: &core::panic::PanicInfo) -> ! { rprintln!("PANIC! {}", info); rprintln!("Location {:?}", info.location()); if let Some(pl) = info.payload().downcast_ref::<&str>() { rprintln!("Payload {:?}", pl); } loop {} } fn color_wheel(byte: u8) -> Color { match byte { 0..=84 => Color(255 - byte * 3, 0, byte * 3), 85..=169 => Color(0, (byte - 85) * 3, 255 - (byte - 85) * 3), _ => Color((byte - 170) * 3, 255 - (byte - 170) * 3, 0), } } #[derive(Copy, Clone, Debug)] struct Color(pub u8, pub u8, pub u8); impl From for (u8, u8, u8) { fn from(value: Color) -> Self { (value.0, value.1, value.2) } }