Code Monkey home page Code Monkey logo

adafruit-alphanum's Introduction

adafruit-alphanum4

Additional features on top of the ht16k33 crate to drive an Adafruit 14-segment LED Alphanumeric Backpack using traits from embedded-hal.

Crate Documentation

Features

  • Sending a u8 to one of the 4 segments
  • Sending an AsciiChar to one of the 4 segments
  • Setting or unsetting the dot associated with one of the 4 segments
  • Formatting a f32 to 1 to 4 segments

Example:

    const DISP_I2C_ADDR: u8 = 112;

    let freq: Hertz = 20.khz().into();

    let mut i2c2 = blocking_i2c(
        I2c::i2c2(
            device.I2C2, 
            (scl_pin, sda_pin),
            Mode::Standard { frequency: freq.0 },
            clocks,
            &mut rcc.apb1,
        ),
        clocks,
        500,
        2,
        500,
        500,
    );

    let mut ht16k33 = HT16K33::new(i2c2, DISP_I2C_ADDR);
    ht16k33.initialize().expect("Failed to initialize ht16k33");

    // Sending individual digits
    ht16k33.update_buffer_with_digit(Index::One, 1);
    ht16k33.update_buffer_with_digit(Index::Two, 2);
    ht16k33.update_buffer_with_digit(Index::Three, 3);
    ht16k33.update_buffer_with_digit(Index::Four, 4);

    // Sending ascii
    ht16k33.update_buffer_with_char(Index::One, AsciiChar::new('A'));
    ht16k33.update_buffer_with_char(Index::Two, AsciiChar::new('B'));

    // Setting the decimal point 
    ht16k33.update_buffer_with_dot(Index::Two, true);

    // Formatting a float using the whole display
    ht16k33.update_buffer_with_float(Index::One, -3.14, 2, 10).unwrap();

    // Putting a character in front of a float
    ht16k33.update_buffer_with_char(Index::One, AsciiChar::new('X'));
    ht16k33.update_buffer_with_float(Index::Two, -3.14, 2, 10).unwrap(); //Display will read "X-3.1"

    // This will panic because there aren't enough digits to display this number
    ht16k33.update_buffer_with_float(Index::One, 12345., 0, 10).expect("Oops"); 

    // Note: none of the above methods actually commit the buffer to the display, call write_display_buffer to actually send it to the display
    ht16k33.write_display_buffer().unwrap()

Performance warning

Due to the api of the ht16k33 crate the display buffer is not directly accessible so each LED that makes up the character is updated sequentially. The way the hardware on this backpack is set up allows a character to be updated by setting a single 16-bit value in the buffer. Iterating over each bit of the 16 every update is clearly not optimal but it's sufficiently fast for my current usage. If the ht16k33 crate is updated to grant mut access to the buffer this can be improved.

License

Free and open source software distributed under the terms of both the MIT License and the Apache License 2.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.