Skip to content

ost-ing/rotary-encoder-embedded

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rotary-encoder-embedded

A rotary encoder library for embedded rust applications

Tests crates.io Documentation Minimum Supported Rust Version

features

fn main() -> ! {
    // Configure DT and CLK pins, typically pullup input
    let rotary_dt = gpio_pin_1.into_pull_up_input()
    let rotary_clk = gpio_pin_2.into_pull_up_input();

    // Initialize the rotary encoder
    let mut rotary_encoder = RotaryEncoder::new(
        rotary_dt,
        rotary_clk,
    ).into_standard_mode();
    
    // Now you can update the state of the rotary encoder and get a direction value. Call this from an update routine, timer task or interrupt
    let _dir = rotary_encoder.update();

    // Alternatively if you want to access the encoder without embedded-hal pin traits and use boolean states, you can use the mode directly:
    let mut raw_encoder = StandardMode::new();
    let _dir = raw_encoder.update(true, false);

    // ...timer initialize at 900Hz to poll the rotary encoder
    loop {}
}

fn timer_interrupt_handler() {
    // ... get rotary encoder 
    let rotary_encoder = ...

    // Update the encoder, which will compute and return its direction
    match rotary_encoder.update() {
        Direction::Clockwise => {
            // Increment some value
        }
        Direction::Anticlockwise => {
            // Decrement some value
        }
        Direction::None => {
            // Do nothing
        }
    }
}

About

A rotary encoder library for embedded Rust applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages