pi-tm1638
1.0
TM1638 library for Raspberry Pi
|
A simple interface to TM1638 based displays for the Raspberry Pi. More...
Go to the source code of this file.
Typedefs | |
typedef struct tm1638_tag | tm1638 |
typedef tm1638 * | tm1638_p |
Functions | |
tm1638_p | tm1638_alloc (uint8_t data, uint8_t clock, uint8_t strobe) |
void | tm1638_free (tm1638_p *t) |
void | tm1638_enable (tm1638_p t, bool enable) |
void | tm1638_set_intensity (tm1638_p t, uint8_t intensity) |
void | tm1638_set_7seg_raw (const tm1638_p t, uint8_t digit, uint8_t n) |
void | tm1638_set_7seg_text (const tm1638_p t, const char *str, uint8_t dots) |
void | tm1638_set_led (const tm1638_p t, uint8_t led, uint8_t cols) |
void | tm1638_set_8leds (const tm1638_p t, uint8_t red, uint8_t green) |
void | tm1638_send_cls (const tm1638_p t) |
uint8_t | tm1638_font (char c) |
uint32_t | tm1638_read_buttons (const tm1638_p t) |
uint8_t | tm1638_read_8buttons (const tm1638_p t) |
A simple interface to TM1638 based displays for the Raspberry Pi.
A simple interface to the TM1638 based displays for the Raspberry Pi.
Dealextreme, doubtless amongst others, sell small boards with eight seven-segment displays, eight red-green LEDs and eight push buttons for less than $10.
The boards are basically just the LEDs and switches, and a TM1638 driver chip. This sits on a two-wire serial bus which makes it fairly easy to connect the boards to a computer/microcontroller of your choice. Of course, one needs a little bit of software. This is such a library for the Raspberry Pi.
#include <bcm2835.h> #include <tm1638.h> ... if (!bcm2835_init()) { ... } tm1638_p t = tm1638_alloc(17, 21, 22); if (!t) { ... } tm1638_set_7seg_text(t, "Hello!", 0xc0); while(...) { uint8_t x = tm1638_read_8buttons(t); tm1638_set_8leds(t, 0, x); } tm1638_free(&t);
All of the hardware interfacing is done via Mike McCauley's excellent bcm2835 library, so you'll need to install that first. Get it from http://www.open.com.au/mikem/bcm2835/
Inevitably people have already done all this for with an Arduino, and that made it easier to write this:
This isn't really a port of Ricardo's code: I wanted a different API. However, I did copy his nice 7-segment font, and his code was very helpful when it came to understanding the data-sheet.
Thank you to everyone.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details at http://www.gnu.org/copyleft/gpl.html
Definition in file tm1638.h.
typedef struct tm1638_tag tm1638 |
Forward declaration of the tm1638 structure. Users of the library should treat this as an opaque object and all interaction with the struct will be indirect.
That is, the library will allocate and free all the structs, so your code should only contain pointers to tm1638 structs, not the structs themselves.
tm1638_p tm1638_alloc | ( | uint8_t | data, |
uint8_t | clock, | ||
uint8_t | strobe | ||
) |
Allocation and initialization function, aka constructor.
NOTES:
All the parameters specify the pins we've connected to the TM1638 board:
data | Pin used for data. |
clock | Pin used for clock. |
strobe | Pin used for strobe. |
void tm1638_enable | ( | tm1638_p | t, |
bool | enable | ||
) |
uint8_t tm1638_font | ( | char | c | ) |
void tm1638_free | ( | tm1638_p * | t | ) |
uint8_t tm1638_read_8buttons | ( | const tm1638_p | t | ) |
uint32_t tm1638_read_buttons | ( | const tm1638_p | t | ) |
Read the 32-bit button input register. The bit order in here isn't helpful for the standard boards with eight buttons on them: see tm1638_read_8buttons() instead.
t | Pointer to the tm1638 of interest. |
void tm1638_send_cls | ( | const tm1638_p | t | ) |
void tm1638_set_7seg_raw | ( | const tm1638_p | t, |
uint8_t | digit, | ||
uint8_t | n | ||
) |
void tm1638_set_7seg_text | ( | const tm1638_p | t, |
const char * | str, | ||
uint8_t | dots | ||
) |
void tm1638_set_8leds | ( | const tm1638_p | t, |
uint8_t | red, | ||
uint8_t | green | ||
) |
Set the status of all eight LEDs at once
t | Pointer to the tm1638 of interest. |
red | A byte's worth of red data (MSB is leftmost). |
green | A byte's worth of green data (MSB is leftmost). |
The ordering might seem odd, but makes the display a sensible binary rendition of red & green.
void tm1638_set_intensity | ( | tm1638_p | t, |
uint8_t | intensity | ||
) |