#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, delay::Delay, system::SystemControl, gpio::{OutputOpenDrain, Io}};
use tm1637_embedded_hal::{blocking::TM1637, demo::blocking::Demo, Brightness};

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);
    let clocks = ClockControl::max(system.clock_control).freeze();
    let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

    let clk_pin = io.pins.gpio4;
    let dio_pin = io.pins.gpio19;

    let delay = Delay::new(&clocks);
    let clk = OutputOpenDrain::new(clk_pin, esp_hal::gpio::Level::Low, esp_hal::gpio::Pull::None);
    let dio = OutputOpenDrain::new(dio_pin, esp_hal::gpio::Level::Low, esp_hal::gpio::Pull::None);

    let mut tm = TM1637::builder(clk, dio, delay).build();
    
    // Initialize the display.
    // Clear the display and set the initial brightness.
    tm.init().unwrap();

    // Change the brightness
    tm.write_brightness(Brightness::L3).unwrap();

    let delay = Delay::new(&clocks);
    let mut demo = Demo::new(tm, delay, 500);
    loop {
        demo.rotating_circle(20, 200).unwrap();
        demo.time(10, 500).unwrap();
        demo.on_off(10, 200).unwrap();
        demo.moving_segments().unwrap();
        demo.moving_digits().unwrap();
        demo.countdown().unwrap();
        demo.moving_up_chars().unwrap();
        demo.moving_lo_chars().unwrap();
        demo.moving_special_chars().unwrap();
    }
}
Loading
esp32-c3-rust-1
4-Digit Display