diff --git a/src/main.rs b/src/main.rs index 3fd840d..ea150a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #![no_main] use arduino_hal::prelude::*; +use embedded_hal::digital::OutputPin; // NOTE: 115200 @ 16MHz is 3.5% off, try 9600 or 1M if it causes issues (https://wormfood.net/avrbaudcalc.php) const SERIAL_BAUD: u32 = 115200; @@ -36,6 +37,12 @@ fn panic(info: &core::panic::PanicInfo) -> ! { } } +enum SegmentState { + Num(u8), + Minus, + Dot, +} + #[arduino_hal::entry] fn main() -> ! { let dp = arduino_hal::Peripherals::take().unwrap(); @@ -46,9 +53,84 @@ fn main() -> ! { ufmt::uwriteln!(&mut serial, "Hello from Arduino!").unwrap_infallible(); + // let mut kd_KN = pins..into_input(); + // let mut kd_KO = *pins.a.into_output(); + let mut kd_d1_1c = pins.d2.into_output(); + let mut kd_d2_5div = pins.d3.into_output(); + let mut kd_d3_6mul = pins.d4.into_output(); + let mut kd_d4_7up = pins.a3.into_output(); + let mut kd_d5_8e = pins.a2.into_output(); + let mut kd_d6_90 = pins.d7.into_output(); + let mut kd_d7_2down = pins.a1.into_output(); + let mut kd_d8_3plus = pins.d11.into_output(); + let mut kd_d9_4min = pins.d12.into_output(); + + let mut kd_seg_a = pins.d5.into_output(); + kd_seg_a.set_high(); + let mut kd_seg_b = pins.d8.into_output(); + kd_seg_b.set_high(); + let mut kd_seg_c = pins.d10.into_output(); + kd_seg_c.set_high(); + let mut kd_seg_d = pins.a5.into_output(); + kd_seg_d.set_high(); + let mut kd_seg_e = pins.d9.into_output(); + kd_seg_e.set_high(); + let mut kd_seg_f = pins.d6.into_output(); + kd_seg_f.set_high(); + let mut kd_seg_g = pins.a0.into_output(); + kd_seg_g.set_high(); + let mut kd_seg_dp = pins.a4.into_output(); + kd_seg_dp.set_high(); + loop { - led.toggle(); - arduino_hal::delay_ms(1000); - ufmt::uwrite!(&mut serial, ".").unwrap_infallible(); + for d in 1u8..=9 { + match d { + 1 => { + kd_d9_4min.set_low(); + kd_d1_1c.set_high(); + } + 2 => { + kd_d1_1c.set_low(); + kd_d2_5div.set_high(); + } + 3 => { + kd_d2_5div.set_low(); + kd_d3_6mul.set_high(); + } + 4 => { + kd_d3_6mul.set_low(); + kd_d4_7up.set_high(); + } + 5 => { + kd_d4_7up.set_low(); + kd_d5_8e.set_high(); + } + 6 => { + kd_d5_8e.set_low(); + kd_d6_90.set_high(); + } + 7 => { + kd_d6_90.set_low(); + kd_d7_2down.set_high(); + } + 8 => { + kd_d7_2down.set_low(); + kd_d8_3plus.set_high(); + } + 9 => { + kd_d8_3plus.set_low(); + kd_d9_4min.set_high(); + } + _ => unreachable!(), + }; + kd_seg_g.set_low(); + arduino_hal::delay_ms(1); + } } + + // loop { + // led.toggle(); + // arduino_hal::delay_ms(1000); + // ufmt::uwrite!(&mut serial, ".").unwrap_infallible(); + // } }