segment-display
Arduino library to drive a multiplexed segment display
Public Member Functions | Static Public Attributes | List of all members
SegmentDisplay::Driver< NUM_DIGITS > Class Template Reference

Driver for a multiplexed segment display. More...

#include <segment_display.h>

Public Member Functions

 Driver (std::initializer_list< uint8_t > digit_pins, std::initializer_list< uint8_t > segment_pins)
 Create a new driver instance using the given pins. More...
 
void setDigits (std::initializer_list< uint8_t > digits)
 Change the digits to the given ones. More...
 
void setDigit (size_t num, uint8_t digit)
 Change the digit at index num to the given one. More...
 
void setSegments (size_t num, uint8_t segments)
 Change the digit at index num to the given segments. More...
 
void refresh (unsigned int light_time=0)
 Refresh on the display. More...
 

Static Public Attributes

static const size_t EMPTY = 16
 Turn all segments off.
 
static const size_t DASH = 17
 Only enable the segment in the middle (G).
 

Detailed Description

template<size_t NUM_DIGITS>
class SegmentDisplay::Driver< NUM_DIGITS >

Driver for a multiplexed segment display.

Template Parameters
NUM_DIGITSSpecifies the number of digits of the segment display.

Example

Seg seg({2, 3, 4, 5}, {6, 7, 8, 9, 10, 11, 12});
seg.setDigits({Seg::DASH, 4, 2});
seg.setSegments(3, 0b00001000); // underscore
void loop() {
seg.refresh();
}

Definition at line 52 of file segment_display.h.

Constructor & Destructor Documentation

template<size_t NUM_DIGITS>
SegmentDisplay::Driver< NUM_DIGITS >::Driver ( std::initializer_list< uint8_t >  digit_pins,
std::initializer_list< uint8_t >  segment_pins 
)
inline

Create a new driver instance using the given pins.

Parameters
digit_pinsExactly NUM_DIGITS pins to use for the led cathodes of each digit.
segment_pins7 or 8 pins to use for the segments (a to g/h).

Definition at line 64 of file segment_display.h.

Member Function Documentation

template<size_t NUM_DIGITS>
void SegmentDisplay::Driver< NUM_DIGITS >::refresh ( unsigned int  light_time = 0)
inline

Refresh on the display.

Turns on the needed segments of all digits for a short amount of time. This must be called repeatedly in your main loops to trick the human brain into believing the display is constantly lit.

Parameters
light_timeThe amount of time each segment is lit up. The default of 0 is sufficient for most cases.

Definition at line 126 of file segment_display.h.

template<size_t NUM_DIGITS>
void SegmentDisplay::Driver< NUM_DIGITS >::setDigit ( size_t  num,
uint8_t  digit 
)
inline

Change the digit at index num to the given one.

All digits passed through the seven segment decoder, so you can pass decimal digits and the constants defined in this class.

Parameters
numThe index of the digit to change
digitThe new digit

Definition at line 101 of file segment_display.h.

template<size_t NUM_DIGITS>
void SegmentDisplay::Driver< NUM_DIGITS >::setDigits ( std::initializer_list< uint8_t >  digits)
inline

Change the digits to the given ones.

See also
setDigit()
Parameters
digitsA list of exactly NUM_DIGITS digits.

Definition at line 87 of file segment_display.h.

template<size_t NUM_DIGITS>
void SegmentDisplay::Driver< NUM_DIGITS >::setSegments ( size_t  num,
uint8_t  segments 
)
inline

Change the digit at index num to the given segments.

This functions bypasses the decimal decoder, so every segment can be enabled independently.

Parameters
numThe index of the digit to change.
segmentsThe new segments, where the LSB is segment a.

Definition at line 113 of file segment_display.h.


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