Robot 7-segment Display, v1.2.0
Posted on

The library for controlling a 7-segment display.
Add the DisplayGroup structure that unions the Display and DisplaySelector structures and displays the passed characters; support transformation of the Display and DisplaySelector structures to the instance that will set an inverted voltage level.
Change Log
- structures:
- the
Displaystructure:- supports transformation to the instance that will set an inverted voltage level;
- the
DisplaySelectorstructure:- supports transformation to the instance that will set an inverted voltage level;
- the
DisplayGroupstructure unions theDisplayandDisplaySelectorstructures and displays the passed characters:- uses a built-in non-blocking timer to switch sub-displays of a multiplexed display;
- erases the previous displayed character to avoid affecting the next display.
- the
Features
- possibilities:
- controlling a single display;
- controlling a multiplexed display;
- structures:
- the
Characterstructure represents a character and keeps a set of specific segments that should be active for displaying this character:- supports transformation to the same character with a decimal point;
- supports transformation to the same character without a decimal point;
- the
Displaystructure represents a single display and keeps mapping between segments and pins to which they are connected:- supports transformation to the instance that will set an inverted voltage level;
- the
DisplaySelectorstructure controls a multiplexed display by switching its sub-displays, and keeps a set of pins using for this:- supports transformation to the instance that will set an inverted voltage level;
- the
DisplayGroupstructure unions theDisplayandDisplaySelectorstructures and displays the passed characters:- uses a built-in non-blocking timer to switch sub-displays of a multiplexed display;
- erases the previous displayed character to avoid affecting the next display.
- the
Examples
A multiplexed display stopwatch:
#include <Character.h>
#include <Display.h>
#include <PinForSegment.h>
#include <DisplaySelector.h>
#include <DisplayGroup.h>
#include <InfiniteTimer.h>
#include <ClockFunc.h>
#include <stdint.h>
using namespace irenica_ideas::robot_7_segment_display;
using namespace irenica_ideas::robot_timer;
constexpr auto DISPLAY_QUANTITY = 4;
constexpr auto DECIMAL_POINT_INDEX = 1;
constexpr auto COUNTER_UPDATE_DELAY_IN_S = 0.1;
constexpr auto DISPLAY_GROUP_UPDATE_DELAY_IN_S = 0.002;
const Character digits[] = {
Character(0x7e), // digit 0
Character(0x30), // digit 1
Character(0x6d), // digit 2
Character(0x79), // digit 3
Character(0x33), // digit 4
Character(0x5b), // digit 5
Character(0x5f), // digit 6
Character(0x70), // digit 7
Character(0x7f), // digit 8
Character(0x7b) // digit 9
};
// TODO: specify your own pin for every segment.
const auto display = Display(
PinForSegment<'a'>{2},
PinForSegment<'b'>{3},
PinForSegment<'c'>{5},
PinForSegment<'d'>{7},
PinForSegment<'e'>{11},
PinForSegment<'f'>{13},
PinForSegment<'g'>{17},
PinForSegment<'p'>{19}
);
// TODO: specify your own pin for every sub-display.
const auto displaySelector = makeDisplaySelector(23, 29, 31, 37);
auto counterUpdateTimer =
InfiniteTimer(COUNTER_UPDATE_DELAY_IN_S, clockForArduino);
uint8_t counterDigits[DISPLAY_QUANTITY] = {};
Character characters[DISPLAY_QUANTITY] = {};
auto displayGroup = makeDisplayGroup(
characters,
&display,
&displaySelector,
DISPLAY_GROUP_UPDATE_DELAY_IN_S,
clockForArduino
);
void setup() {
display.initialize();
displaySelector.initialize();
}
void loop() {
counterUpdateTimer.update();
displayGroup.update();
// update the counter
if (counterUpdateTimer.didItTick()) {
auto willBeOverflowed = true;
for (
auto index = 0;
index < DISPLAY_QUANTITY && willBeOverflowed;
++index
) {
willBeOverflowed = counterDigits[index] == 9;
counterDigits[index] = willBeOverflowed ? 0 : counterDigits[index] + 1;
// show the first character on the first sub-display, the second character
// on the second sub-display, etc.
characters[index] = digits[counterDigits[index]];
if (index == DECIMAL_POINT_INDEX) {
characters[index] = characters[index].withDecimalPoint();
}
}
}
}
Photos
Without erasure of the previous character

With erasure of the previous character
