|
| 1 | +#![no_std] |
| 2 | +#![no_main] |
| 3 | + |
| 4 | +use panic_halt as _; |
| 5 | + |
| 6 | +const NUM_CHARS: usize = 8; |
| 7 | +const MESSAGE: &[u8] = b"Stella and Beau and Stevie and Louie and "; |
| 8 | + |
| 9 | +#[arduino_hal::entry] |
| 10 | +fn main() -> ! { |
| 11 | + let dp = arduino_hal::Peripherals::take().unwrap(); |
| 12 | + let pins = arduino_hal::pins!(dp); |
| 13 | + |
| 14 | + let mut led_pin = pins.d13.into_output(); |
| 15 | + |
| 16 | + // high impedance pins |
| 17 | + pins.sck.into_floating_input(); |
| 18 | + pins.mosi.into_floating_input(); |
| 19 | + pins.d9.into_floating_input(); |
| 20 | + pins.d5.into_floating_input(); |
| 21 | + |
| 22 | + let mut display = hcms29xx::Hcms29xx::new( |
| 23 | + NUM_CHARS, // Number of characters in the display |
| 24 | + pins.d0.into_output().downgrade(), // Data pin |
| 25 | + pins.d1.into_output().downgrade(), // Clock pin |
| 26 | + pins.d11.into_output().downgrade(), // Chip select pin |
| 27 | + pins.d2.into_output().downgrade(), // Reset pin |
| 28 | + Some(pins.d3.into_output().downgrade()), // Optional: Enable pin |
| 29 | + Some(pins.d6.into_output().downgrade()), // Optional: Write pin |
| 30 | + Some(pins.d10.into_output().downgrade()), // Optional: Read pin |
| 31 | + ) |
| 32 | + .unwrap(); |
| 33 | + display.begin().unwrap(); |
| 34 | + display.display_unblank().unwrap(); |
| 35 | + display.set_current(1).unwrap(); |
| 36 | + //display.set_int_osc().unwrap(); now default |
| 37 | + |
| 38 | + // test max current/power draw |
| 39 | + // display.set_current(crate::hcms29xx::constants::control_word_0::current::MAX_12_8MA).unwrap(); |
| 40 | + // display.set_brightness(crate::hcms29xx::constants::control_word_0::MAX_BRIGHTNESS).unwrap(); |
| 41 | + |
| 42 | + let mut cursor: usize = 0; |
| 43 | + let mut count: u16 = 0; |
| 44 | + let mut buf: [u8; NUM_CHARS] = [0; NUM_CHARS]; |
| 45 | + loop { |
| 46 | + count = (count + 1) % 10000; |
| 47 | + if (count % 30) == 0 { |
| 48 | + cursor = (cursor + 1) % MESSAGE.len(); |
| 49 | + } |
| 50 | + if (count % 500) == 0 { |
| 51 | + led_pin.toggle(); |
| 52 | + } |
| 53 | + |
| 54 | + for i in 0..4 { |
| 55 | + let index = (cursor + i as usize) % MESSAGE.len(); |
| 56 | + buf[i as usize] = MESSAGE[index]; |
| 57 | + } |
| 58 | + |
| 59 | + let mut count_dec = count; |
| 60 | + for i in (0..4).rev() { |
| 61 | + buf[i as usize + 4] = if count_dec > 0 { |
| 62 | + (count_dec % 10) as u8 + b'0' |
| 63 | + } else { |
| 64 | + b' ' |
| 65 | + }; |
| 66 | + count_dec /= 10; |
| 67 | + } |
| 68 | + |
| 69 | + display.print_c_string(&buf).unwrap(); |
| 70 | + arduino_hal::delay_ms(1); |
| 71 | + } |
| 72 | +} |
0 commit comments