Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
TM1637Display Class Reference

Public Member Functions

 TM1637Display (uint8_t pinClk, uint8_t pinDIO)
 
void setBrightness (uint8_t brightness, bool on=true)
 
void setSegments (const uint8_t segments[], uint8_t length=4, uint8_t pos=0)
 
void showNumberDec (int num, bool leading_zero=false, uint8_t length=4, uint8_t pos=0)
 
void showNumberDecEx (int num, uint8_t dots=0, bool leading_zero=false, uint8_t length=4, uint8_t pos=0)
 
uint8_t encodeDigit (uint8_t digit)
 

Protected Member Functions

void bitDelay ()
 
void start ()
 
void stop ()
 
bool writeByte (uint8_t b)
 

Constructor & Destructor Documentation

TM1637Display::TM1637Display ( uint8_t  pinClk,
uint8_t  pinDIO 
)

Initialize a TM1637Display object, setting the clock and data pins.

Parameters
pinClk- The number of the digital pin connected to the clock pin of the module
pinDIO- The number of the digital pin connected to the DIO pin of the module

Member Function Documentation

uint8_t TM1637Display::encodeDigit ( uint8_t  digit)

Translate a single digit into 7 segment code

The method accepts a number between 0 - 15 and converts it to the code required to display the number on a 7 segment display. Numbers between 10-15 are converted to hexadecimal digits (A-F)

Parameters
digitA number between 0 to 15
Returns
A code representing the 7 segment image of the digit (LSB - segment A; bit 6 - segment G; bit 7 - always zero)
void TM1637Display::setBrightness ( uint8_t  brightness,
bool  on = true 
)

Sets the brightness of the display.

The setting takes effect when a command is given to change the data being displayed.

Parameters
brightnessA number from 0 (lowes brightness) to 7 (highest brightness)
onTurn display on or off
void TM1637Display::setSegments ( const uint8_t  segments[],
uint8_t  length = 4,
uint8_t  pos = 0 
)

Display arbitrary data on the module

This function receives raw segment values as input and displays them. The segment data is given as a byte array, each byte corresponding to a single digit. Within each byte, bit 0 is segment A, bit 1 is segment B etc. The function may either set the entire display or any desirable part on its own. The first digit is given by the pos argument with 0 being the leftmost digit. The length argument is the number of digits to be set. Other digits are not affected.

Parameters
segmentsAn array of size length containing the raw segment values
lengthThe number of digits to be modified
posThe position from which to start the modification (0 - leftmost, 3 - rightmost)
void TM1637Display::showNumberDec ( int  num,
bool  leading_zero = false,
uint8_t  length = 4,
uint8_t  pos = 0 
)

Displayes a decimal number

Dispalyes the given argument as a decimal number

Parameters
numThe number to be shown
leading_zeroWhen true, leading zeros are displayed. Otherwise unnecessary digits are blank
lengthThe number of digits to set. The user must ensure that the number to be shown fits to the number of digits requested (for example, if two digits are to be displayed, the number must be between 0 to 99)
posThe position most significant digit (0 - leftmost, 3 - rightmost)
void TM1637Display::showNumberDecEx ( int  num,
uint8_t  dots = 0,
bool  leading_zero = false,
uint8_t  length = 4,
uint8_t  pos = 0 
)

Displayes a decimal number, with dot control

Dispalyes the given argument as a decimal number. The dots between the digits (or colon) can be individually controlled

Parameters
numThe number to be shown
dotsDot/Colon enable. The argument is a bitmask, with each bit corresponding to a dot between the digits (or colon mark, as implemented by each module). i.e. For displays with dots between each digit:
  • 0.000 (0b10000000)
  • 00.00 (0b01000000)
  • 000.0 (0b00100000)
  • 0.0.0.0 (0b11100000) For displays with just a colon:
  • 00:00 (0b01000000) For displays with dots and colons colon:
  • 0.0:0.0 (0b11100000)
leading_zeroWhen true, leading zeros are displayed. Otherwise unnecessary digits are blank
lengthThe number of digits to set. The user must ensure that the number to be shown fits to the number of digits requested (for example, if two digits are to be displayed, the number must be between 0 to 99)
posThe position least significant digit (0 - leftmost, 3 - rightmost)