1 #ifndef _SEGMENT_DISPLAY     2 #define _SEGMENT_DISPLAY     4 #include <avr/pgmspace.h>     6 #include "std/initializer_list.h"    11 const PROGMEM uint8_t DECODER[] = {
    51 template<
size_t NUM_DIGITS>
    57         const static size_t DASH = 17;
    64         Driver(std::initializer_list<uint8_t> digit_pins, std::initializer_list<uint8_t> segment_pins) {
    66             for(
auto pin : digit_pins) {
    67                 if(i >= NUM_DIGITS) 
break;
    68                 this->digit_pins[i++] = pin;
    72             for(
auto pin : segment_pins) {
    74                 this->segment_pins[i++] = pin;
    78             for(i = 0; i < NUM_DIGITS; ++i) {
    87         void setDigits(std::initializer_list<uint8_t> digits) {
    89             for(
auto digit : digits) {
   102             if(num >= NUM_DIGITS || digit > 17) 
return;
   103             this->state[num] = pgm_read_byte_near(DECODER + digit);
   114             if(num >= NUM_DIGITS) 
return;
   115             this->state[num] = segments;
   128             for(
auto segment : segment_pins) {
   130                 if(segment < 0) 
continue;
   132                 digitalWrite(segment, HIGH);
   135                 for(
auto digitState : state) {
   136                     digitalWrite(digit_pins[j++],(digitState & 1 << i) == 0);
   140                 delayMicroseconds(light_time);
   143                 for(
auto digitState : state) {
   144                     digitalWrite(digit_pins[j++], HIGH);
   147                 digitalWrite(segment, LOW);
   153         uint8_t segment_pins[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
   154         uint8_t digit_pins[NUM_DIGITS];
   156         uint8_t state[NUM_DIGITS];
   161 #endif // _SEGMENT_DISPLAY Driver(std::initializer_list< uint8_t > digit_pins, std::initializer_list< uint8_t > segment_pins)
Create a new driver instance using the given pins. 
 
static const size_t EMPTY
Turn all segments off. 
 
void refresh(unsigned int light_time=0)
Refresh on the display. 
 
void setSegments(size_t num, uint8_t segments)
Change the digit at index num to the given segments. 
 
Driver for a multiplexed segment display. 
 
void setDigit(size_t num, uint8_t digit)
Change the digit at index num to the given one. 
 
void setDigits(std::initializer_list< uint8_t > digits)
Change the digits to the given ones. 
 
static const size_t DASH
Only enable the segment in the middle (G).