Skip to content

Commit

Permalink
Allow users to set the bit delay via constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
avishorp committed Oct 30, 2018
1 parent 6b39729 commit fd89c1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions TM1637Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ const uint8_t digitToSegment[] = {

static const uint8_t minusSegments = 0b01000000;

TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO)
TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay)
{
// Copy the pin numbers
m_pinClk = pinClk;
m_pinDIO = pinDIO;
m_bitDelay = bitDelay;

// Set the pin direction and default value.
// Both pins are set as inputs, allowing the pull-up resistors to pull them up
Expand Down Expand Up @@ -177,7 +178,7 @@ void TM1637Display::showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots, bo

void TM1637Display::bitDelay()
{
delayMicroseconds(100);
delayMicroseconds(m_bitDelay);
}

void TM1637Display::start()
Expand Down
7 changes: 6 additions & 1 deletion TM1637Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define SEG_F 0b00100000
#define SEG_G 0b01000000

#define DEFAULT_BIT_DELAY 100

class TM1637Display {

public:
Expand All @@ -35,7 +37,9 @@ class TM1637Display {
//!
//! @param pinClk - The number of the digital pin connected to the clock pin of the module
//! @param pinDIO - The number of the digital pin connected to the DIO pin of the module
TM1637Display(uint8_t pinClk, uint8_t pinDIO);
//! @param bitDelay - The delay, in microseconds, between bit transition on the serial
//! bus connected to the display
TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay = DEFAULT_BIT_DELAY);

//! Sets the brightness of the display.
//!
Expand Down Expand Up @@ -155,6 +159,7 @@ class TM1637Display {
uint8_t m_pinClk;
uint8_t m_pinDIO;
uint8_t m_brightness;
unsigned int m_bitDelay;
};

#endif // __TM1637DISPLAY__

0 comments on commit fd89c1b

Please sign in to comment.