3642BS driver for embedded devices

banner

Makes displaying stuff on the 3642BS easy.

Allows you to display dec and hex numbers as well as the time and your own custom characters with a single line of code. rs display.clear().unwrap(); display.number(1234).unwrap(); display.hex(0xF3E2).unwrap(); display.time(10, 30).unwrap(); // ===A=== // ‖ ‖ // Make your own custom characters: // F B let letter_c = SEG_A | SEG_F | SEG_E | SEG_D; // ‖ ‖ let letter_o = SEG_G | SEG_E | SEG_C | SEG_D; // ===G=== let letter_l = SEG_F | SEG_E | SEG_D; // ‖ ‖ let text_cool = [letter_c, letter_o, letter_o, letter_l]; // E C // ‖ ‖ display.custom(text_cool).unwrap(); // ===D===

How to use

Include the library on your cargo.toml toml sevseg_3642bs = { git = "https://gitlab.com/slusheea/sevseg-3642bs" }

Define which pins are going to be used: rs let mut display = Display::new( pins.gpio16.into_push_pull_output(), // Segment A pins.gpio17.into_push_pull_output(), // Segment B pins.gpio18.into_push_pull_output(), // Segment C pins.gpio19.into_push_pull_output(), // Segment D pins.gpio20.into_push_pull_output(), // Segment E pins.gpio21.into_push_pull_output(), // Segment F pins.gpio22.into_push_pull_output(), // Segment G pins.gpio26.into_push_pull_output(), // Two dots pins.gpio15.into_push_pull_output(), // Digit 1 pins.gpio14.into_push_pull_output(), // Digit 2 pins.gpio13.into_push_pull_output(), // Digit 3 pins.gpio12.into_push_pull_output(), // Digit 4 delay, // Your HAL's delay object );

Since the display has to be multiplexed, delays can't be used on the same core the library is on, or the display will freeze on a single digit. For this reason I recommend using alarms or timers.

Example using Alarm0 (On the rpi pico): ```rs // Other code like defining the pins and importing libraries. // You'll need to import fugit::ExtU32

let mut timer = bsp::hal::Timer::new(pac.TIMER, &mut pac.RESETS);

// Other code like defining the Display struct

let alarm = timer.alarm_1().unwrap();

loop { // Other code like calculating "value"

let _ = alarm.schedule(100_000.micros());

while !alarm.finished() {
    display.number(value).unwrap();
}

} ```

Example using Timer (on the rpi pico): ```rs // Other code like defining the pins and importing libraries

let mut timer = bsp::hal::Timer::new(pac.TIMER, &mut pac.RESETS); let mut countdown = timer.countdown();

// Other code like defining the Display struct

let mut prevtime = timer.getcounter();

loop { // Other code like calculating "value"

while timer.get_counter() < prev_time + 100_000 {
    display.number(value);
}
prev_time = timer.get_counter();

} ```

Example using the Real Time Clock (on the pi pico): ```rs let mut watchdog = Watchdog::new(pac.WATCHDOG);

let clocks = clocks::initclocksandplls( XTALFREQHZ, pac.XOSC, pac.CLOCKS, pac.PLLSYS, pac.PLL_USB, &mut pac.RESETS, &mut watchdog, ).ok().unwrap();

let initialdate = DateTime { year: 2023, month: 1, day: 27, dayof_week: DayOfWeek::Friday, hour: 18, minute: 46, second: 0, };

let realtimeclock = RealTimeClock::new(pac.RTC, clocks.rtcclock, &mut pac.RESETS, initialdate).unwrap();

let mut prevtime = realtime_clock.now().unwrap().second;

loop { let mut currenttime = realtimeclock.now().unwrap().second; while currenttime == prevtime { display .time( realtimeclock.now().unwrap().minute, currenttime, currenttime, ) .unwrap(); currenttime = realtimeclock.now().unwrap().second; } prevtime = currenttime; } ```

More info on the docs. Clone the repo and run cargo doc --open to view