led_tm1637: allow number to be displayed without leading 0
This commit is contained in:
parent
afd5bef309
commit
c30b3ecb48
|
@ -283,15 +283,36 @@ bool led_tm1637_brightness(enum led_tm1637_brightness_t brightness)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool led_tm1637_number(uint16_t number)
|
||||
bool led_tm1637_number(uint16_t number, bool zero)
|
||||
{
|
||||
uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal
|
||||
uint8_t data[] = { 0xc0, ascii_7segments[((number / 1000) % 10) + '0' - ' '], ascii_7segments[((number / 100) % 10) + '0' - ' '], ascii_7segments[((number / 10) % 10) + '0' - ' '], ascii_7segments[((number / 1) % 10) + '0' - ' '] }; // set address C0H and add data
|
||||
|
||||
if (led_tm1637_write(write_data,LENGTH(write_data)) && led_tm1637_write(data,LENGTH(data))) { // send commands
|
||||
return true;
|
||||
const uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal
|
||||
const uint8_t digits[] = { // digits to display
|
||||
(number / 1000) % 10,
|
||||
(number / 100) % 10,
|
||||
(number / 10) % 10,
|
||||
(number / 1) % 10,
|
||||
};
|
||||
uint8_t data[] = { 0xc0, 0, 0, 0, 0}; // number to be displayed
|
||||
// convert digits to text to be displayed
|
||||
if (0 == digits[0] && !zero) {
|
||||
data[1] = ascii_7segments[' ' - ' '];
|
||||
} else {
|
||||
data[1] = ascii_7segments[digits[0] + '0' - ' '];
|
||||
}
|
||||
return false;
|
||||
if (0 == digits[0] && 0 == digits[1] && !zero) {
|
||||
data[2] = ascii_7segments[' ' - ' '];
|
||||
} else {
|
||||
data[2] = ascii_7segments[digits[1] + '0' - ' '];
|
||||
}
|
||||
if (0 == digits[0] && 0 == digits[1] && 0 == digits[2] && !zero) {
|
||||
data[3] = ascii_7segments[' ' - ' '];
|
||||
} else {
|
||||
data[3] = ascii_7segments[digits[2] + '0' - ' '];
|
||||
}
|
||||
data[4] = ascii_7segments[digits[3] + '0' - ' '];
|
||||
|
||||
// display number
|
||||
return led_tm1637_write(write_data, LENGTH(write_data)) && led_tm1637_write(data, LENGTH(data)); // send commands
|
||||
}
|
||||
|
||||
bool led_tm1637_time(uint8_t hours, uint8_t minutes)
|
||||
|
|
|
@ -52,9 +52,10 @@ bool led_tm1637_off(void);
|
|||
bool led_tm1637_brightness(enum led_tm1637_brightness_t brightness);
|
||||
/** display number
|
||||
* @param[in] number number to display (0-9999)
|
||||
* @param[in] zero pad number with zero on the left
|
||||
* @return if transmission succeeded
|
||||
*/
|
||||
bool led_tm1637_number(uint16_t number);
|
||||
bool led_tm1637_number(uint16_t number, bool zero);
|
||||
/** display time
|
||||
* @param[in] hours hours to display (0-99)
|
||||
* @param[in] minutes minutes to display (0-99)
|
||||
|
|
Loading…
Reference in New Issue