Set up properly for a single light

This commit is contained in:
Savanni D'Gerinel 2024-11-03 18:46:06 -05:00
parent 1601d2d806
commit 82ec50f519
1 changed files with 20 additions and 32 deletions

View File

@ -1,8 +1,8 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
use embedded_hal::{delay::DelayNs, digital::OutputPin};
use embedded_hal::spi::SpiBus; use embedded_hal::spi::SpiBus;
use embedded_hal::{delay::DelayNs, digital::OutputPin};
use panic_halt as _; use panic_halt as _;
use rp_pico::hal::gpio::bank0::Gpio0; use rp_pico::hal::gpio::bank0::Gpio0;
use rp_pico::{ use rp_pico::{
@ -21,6 +21,8 @@ use rp_pico::{
pac, Pins, pac, Pins,
}; };
const FPS: u32 = 60;
const MS_PER_FRAME: u32 = 1000 / FPS;
const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // MHz, https://forums.raspberrypi.com/viewtopic.php?t=356764 const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // MHz, https://forums.raspberrypi.com/viewtopic.php?t=356764
#[entry] #[entry]
@ -46,8 +48,6 @@ unsafe fn main() -> ! {
.ok() .ok()
.unwrap(); .unwrap();
// let mut power_light: Pin<Gpio0, FunctionSio<SioOutput>, PullDown> = pins.gpio0.into_function();
// power_light.set_high();
let mut timer = Timer::new(peripherals.TIMER, &mut peripherals.RESETS, &clocks); let mut timer = Timer::new(peripherals.TIMER, &mut peripherals.RESETS, &clocks);
let spi_clk = pins.gpio10.into_function(); let spi_clk = pins.gpio10.into_function();
@ -60,44 +60,32 @@ unsafe fn main() -> ! {
embedded_hal::spi::MODE_1, embedded_hal::spi::MODE_1,
); );
let mut lights: [u8; 126] = [0; 126]; // byte count: 4 for the start frame
lights[124] = 0xff; // 1 * 4 for three lights with 4 bytes per light
lights[125] = 0xff; // 4 for the end frame
for i in 0..30 { // = 20 bytes
lights[(i + 1) * 4 + 0] = 0xe0 + 1; let mut lights: [u8; 12] = [0; 12];
lights[(i + 1) * 4 + 1] = 255; lights[8] = 0xff;
} lights[9] = 0xff;
lights[10] = 0xff;
lights[11] = 0xff;
lights[4] = 0xe0 + 1;
let mut brightness = 1; let mut brightness = 1;
let mut step = 1; let mut step = 1;
loop { loop {
if brightness == 255 && step == 1 { if brightness == 64 && step == 1 {
step = -1; step = -1;
} else if brightness == 1 && step == -1 { } else if brightness == 1 && step == -1 {
step = 1; step = 1;
}; };
for i in 0..30 { lights[5] = brightness as u8;
lights[(i + 1) * 4 + 3] = brightness as u8; lights[6] = 255;
} // lights[7] = brightness as u8;
brightness = brightness + step; brightness = brightness + step;
spi.write(lights.as_slice()); spi.write(lights.as_slice());
timer.delay_ms(10); timer.delay_ms(MS_PER_FRAME);
} }
/*
let pins = (pins.gpio0.into_function(), pins.gpio1.into_function());
let uart = UartPeripheral::new(peripherals.UART0, pins, &mut peripherals.RESETS)
.enable(
UartConfig::new(9600_u32.Hz(), DataBits::Eight, None, StopBits::One),
clocks.peripheral_clock.freq(),
)
.unwrap();
loop {
uart.write_full_blocking(b"Hello World!\r\n");
timer.delay_ms(1000);
}
*/
} }