upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions
TM1637 Class Reference

API for the TM1637 7-Segment Display. More...

Detailed Description

TM1637 is a display controller for LED-based 7-segment displays. It can be used to address and write data to multiple display digits. This driver is based on the Grove version of the TM1637 display that uses 4 digits, thus making it ideal for clock displays, timers, counters, or even score displays in a two-player arcade game.

tm1637.jpeg
bool point = true;
int timezone = -7; // Your UTC offset
time_t rawtime;
struct tm * gmt;
char myTime[5];
fprintf(stdout, "TM1637 Display Example\n");
signal(SIGINT, sig_handler);
TM1637 myDisplay = TM1637(0, 1); // TM1637 on pins 0 (clk) and 1 (dio)
myDisplay.write(0x39, 0x09, 0x09); // Start a box using 7-segment encoding
myDisplay.writeAt(3, ']'); // Finish box using writeAt function
sleep(3); // Wait 3 seconds
while(run)
{
time(&rawtime); // Update raw time
gmt = gmtime(&rawtime); // Get current time
int hour = (gmt) ? gmt->tm_hour : 0;
int min = (gmt) ? gmt->tm_min : 0;
// Format and store the time in 24 hour format
snprintf(myTime, 5, "%2d%02d", (hour + timezone + 24) % 24, min);
myDisplay.write(myTime); // Write to display as string
myDisplay.setColon(point ^= true); // Toggle the dots on the display
sleep(1); // Only update once every second
}

Public Types

enum  M_FAST_GPIO { NO = 0, YES = 1 }
 

Public Member Functions

 TM1637 (int clk_pin, int dio_pin, int bright=3, M_FAST_GPIO mmio=YES)
 
 ~TM1637 ()
 
mraa_result_t write (uint8_t *digits)
 
mraa_result_t write (int d,...)
 
mraa_result_t writeAt (int index, char symbol)
 
mraa_result_t write (std::string digits)
 
void setColon (bool value)
 
void setBrightness (int value)
 

Member Enumeration Documentation

Enum for the memory-mapped GPIO

Constructor & Destructor Documentation

TM1637 ( int  clk_pin,
int  dio_pin,
int  bright = 3,
M_FAST_GPIO  mmio = YES 
)

TM1637 constructor

Parameters
clk_pinClock pin the sensor is connected to
dio_pinData pin the sensor is connected to
brightInitial brightness, from 0 (dark) to 7 (bright) (default is 3)
mmioFast memory-mapped GPIO writes; default is yes
~TM1637 ( )

TM1637 destructor

Member Function Documentation

mraa_result_t write ( uint8_t *  digits)

Writes digits to the display in a 7-segment encoding

Parameters
digitsArray of digits to send to the display
Returns
0 if successful, error code otherwise
mraa_result_t write ( int  d,
  ... 
)

Writes digits to the display in a 7-segment encoding

Parameters
dList of multiple arguments to send to the display
Returns
0 if successful, error code otherwise
mraa_result_t writeAt ( int  index,
char  symbol 
)

Writes a symbol (digit or letter) to the display in a specified index

Parameters
index0-based index of the digit to change from the left
symbolDigit or letter to display
Returns
0 if successful, error code otherwise
mraa_result_t write ( std::string  digits)

Writes all the digits or letters to the display as a string

Parameters
digitsString of symbols to display
Returns
0 if successful, error code otherwise
void setColon ( bool  value)

Toggles the colon between digits on the display

Parameters
valueTrue to turn the colon on, false to turn it off
void setBrightness ( int  value)

Controls the brightness of the display

Parameters
valueBrightness, from 0 (darkest) to 7 (brightest)

The documentation for this class was generated from the following files: