Related to modules: [HW] Motor Module
This library includes usage functions of Homelab's encoders.
configures selected encoder and the input pins. Parameters:
Resets and starts counting the selected encoder. Parameters:
Request of counted encoder impulses. Parameters:
// // Example of using the Homelab's encoders. // The number of pulses is displayed on LCD. // #include <stdio.h> #include <homelab/module/lcd_gfx.h> #include <homelab/delay.h> #include <homelab/module/encoders.h> #include <homelab/module/buzzer.h> #include <homelab/pin.h> // Button pin pin button2 = PIN(C, 1); int main(void) { unsigned short pulses = 0; char text[16]; // Sets buttons pin_setup_input_with_pullup(button2); // Initialization of encoder encoder_init(0); // Reset and start counting encoder_reset_pulses(0); // LCD display initialization lcd_gfx_init(); // Clear display lcd_gfx_clear(); // Turning back light ON lcd_gfx_backlight(true); // Displaying source code name lcd_gfx_goto_char_xy(3, 1); lcd_gfx_write_string("Encoder"); while (true) { pulses = encoder_get_pulses(0); // Generating a string sprintf(text, "Pulsse: %d",pulses); lcd_gfx_goto_char_xy(0, 3); lcd_gfx_write_string(text); // Button 2 is pressed if(!pin_get_debounced_value(button2)) { // Reset and start counting encoder_reset_pulses(0); // Make a beep buzzer_sound (60, 100); // Erase previous number lcd_gfx_write_string(" "); } // Software delay for 10 ms sw_delay_ms(10); } }