48 lines
1.1 KiB
C++
48 lines
1.1 KiB
C++
#ifndef TM1640_HPP
|
|
#define TM1640_HPP
|
|
|
|
#include "driver/gpio.h"
|
|
#include <stdint.h>
|
|
|
|
class TM1640 {
|
|
gpio_num_t clk_pin;
|
|
gpio_num_t dio_pin;
|
|
/// The intensity and display on/off setting.
|
|
uint8_t intensity;
|
|
|
|
void bit_delay();
|
|
void start();
|
|
void stop();
|
|
void shift_out(uint8_t data);
|
|
void send(uint8_t* data, size_t len);
|
|
public:
|
|
TM1640(gpio_num_t clk_pin, gpio_num_t dio_pin);
|
|
|
|
/// Initializes the TM1640 7-segment display.
|
|
void init();
|
|
|
|
/// Clears the display by setting all segments to off.
|
|
void clear_display();
|
|
|
|
/// Sets the segments of a single digit.
|
|
void set_digit(uint8_t digit, uint8_t segments);
|
|
|
|
/// Sets the segments of multiple digits starting at `starting_pos`.
|
|
void set_digits(uint8_t starting_pos, uint8_t* segments, size_t len);
|
|
|
|
/// Sets the intensity from 0-7.
|
|
///
|
|
/// intensity 0 is still on. To turn the display off, use `set_display`().
|
|
void set_intensity(uint8_t intensity);
|
|
|
|
/// Turns the display on or off.
|
|
void set_display(bool on);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // TM1640_HPP
|