AceSegmentWriter  0.4
Write decimal numbers, hex numbers, temperature, clock digits, characters, and strings to seven segment LED modules
Public Member Functions | List of all members
ace_segment::NumberWriter< T_LED_MODULE > Class Template Reference

The NumberWriter supports converting decimal and hexadecimal numbers to segment patterns expected by LedModule. More...

#include <NumberWriter.h>

Public Member Functions

 NumberWriter (PatternWriter< T_LED_MODULE > &patternWriter)
 Constructor.
 
T_LED_MODULE & ledModule ()
 Get the underlying LedModule.
 
PatternWriter< T_LED_MODULE > & patternWriter ()
 Get the underlying PatternWriter.
 
void home ()
 Reset cursor to home.
 
void writeDigit (digit_t c)
 Write the digit c at position pos. More...
 
void writeDigits (const digit_t s[], uint8_t len)
 Write the len hex characters given by s at LED pos.
 
void writeDec2 (uint8_t d, uint8_t padPattern=kPattern0)
 Write a 2-digit decimal number at position digit, right justified with the given padPattern (default kPattern0). More...
 
void writeDec4 (uint16_t dd, uint8_t padPattern=kPattern0)
 Write the 4 digit decimal number dd at pos, right justified, padded with a the padPattern (default kPattern0). More...
 
void writeBcd (uint8_t bcd)
 Write a 2-digit BCD number at position, which involves just printing the number as a hexadecimal number. More...
 
void writeHexByte (uint8_t b)
 Write the 2-digit (8-bit) hexadecimal byte 'b' at pos.
 
void writeHexWord (uint16_t w)
 Write the 4 digit (16-bit) hexadecimal word at pos.
 
uint8_t writeUnsignedDecimal (uint16_t num, int8_t boxSize=0)
 Write the 16-bit unsigned number num as a decimal number at pos. More...
 
uint8_t writeSignedDecimal (int16_t num, int8_t boxSize=0)
 Same as writeUnsignedDecimal() but prepends a '-' sign if negative.
 
void setDecimalPointAt (uint8_t pos, bool state=true)
 Write the decimal point for the pos. More...
 
void clear ()
 Clear the entire display.
 
void clearToEnd ()
 Clear the display from the current position to the end. More...
 

Detailed Description

template<typename T_LED_MODULE>
class ace_segment::NumberWriter< T_LED_MODULE >

The NumberWriter supports converting decimal and hexadecimal numbers to segment patterns expected by LedModule.

The character set includes 0 to F, and a few other characters which should be self-explanatory: kDigitSpace and kDigitMinus.

Template Parameters
T_LED_MODULEthe class of the underlying LED Module, often LedModule but other classes with the same generic public methods can be substituted

Definition at line 72 of file NumberWriter.h.

Member Function Documentation

◆ clearToEnd()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::clearToEnd ( )
inline

Clear the display from the current position to the end.

Useful after calling writeSignedDecimal() and writeUnsignedDecimal() which prints a variable number of digits.

Definition at line 239 of file NumberWriter.h.

◆ setDecimalPointAt()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::setDecimalPointAt ( uint8_t  pos,
bool  state = true 
)
inline

Write the decimal point for the pos.

Clock LED modules will attach the colon segment to one of the decimal points.

Definition at line 227 of file NumberWriter.h.

◆ writeBcd()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::writeBcd ( uint8_t  bcd)
inline

Write a 2-digit BCD number at position, which involves just printing the number as a hexadecimal number.

For example, 0x12 is printed as "12", but 0x1A is printed as "1 ".

Definition at line 159 of file NumberWriter.h.

◆ writeDec2()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::writeDec2 ( uint8_t  d,
uint8_t  padPattern = kPattern0 
)
inline

Write a 2-digit decimal number at position digit, right justified with the given padPattern (default kPattern0).

If the number is greater than 100, then print " " (2 spaces). Useful for month, day, hour, minute, second.

Parameters
ddecimal value to write
padPatternleading pattern, usually kPatternSpace or kPattern0

Definition at line 113 of file NumberWriter.h.

◆ writeDec4()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::writeDec4 ( uint16_t  dd,
uint8_t  padPattern = kPattern0 
)
inline

Write the 4 digit decimal number dd at pos, right justified, padded with a the padPattern (default kPattern0).

If the number is greater than 10000, print 4 spaces.

Definition at line 134 of file NumberWriter.h.

◆ writeDigit()

template<typename T_LED_MODULE >
void ace_segment::NumberWriter< T_LED_MODULE >::writeDigit ( digit_t  c)
inline

Write the digit c at position pos.

If c falls outside the valid range of the kDigitPatterns set, a kDigitSpace character is printed instead.

Definition at line 93 of file NumberWriter.h.

◆ writeUnsignedDecimal()

template<typename T_LED_MODULE >
uint8_t ace_segment::NumberWriter< T_LED_MODULE >::writeUnsignedDecimal ( uint16_t  num,
int8_t  boxSize = 0 
)
inline

Write the 16-bit unsigned number num as a decimal number at pos.

The lead padding character is always kPatternSpace.

Parameters
numunsigned decimal number, 0-65535
boxSizesize of box. This is meant to be similar to the "%-5d" or "%5d" specifier to the printf() function. The actual digits may spill over the recommended box size.
  • 0 means no boxing, printing from left
  • > 0 means right justified inside box
  • < 0 means left justified inside box
Returns
number of characters actually written, even if the characters bled over the end of the LED segments

Definition at line 199 of file NumberWriter.h.


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