https://miguelpynto.github.io/ShiftDisplay/
by MiguelPynto
Arduino library for driving 7-segment displays using shift registers
Connect Arduino board to shift registers:
Connect shift registers to display(s):
#include <ShiftDisplay.h>
ShiftDisplay display(COMMON_CATHODE, 3);
void setup() {
for (int i = 3; i > 0; i--) {
// store number and show it for 400ms
display.set(i, ALIGN_CENTER);
display.show(400);
// add dot to stored number and show it for 400ms
display.changeDot(1);
display.show(400);
}
display.set("GO"); // store "GO"
}
void loop() {
display.update(); // show stored "GO" while in loop
}
ShiftDisplay()
Create a ShiftDisplay object, initialize the library using the interface pins, display properties and configurations. A display can be set as a whole, or divided by sections. Sections can be a logical separation (for example hours and minutes on a 4 digit clock display), or a physical separation (for example timer and score on a scoreboard with multiple displays).
latchPin
, clockPin
, dataPin
(int): number of the Arduino digital pins connected to the latch, clock and data pins of the shift registers;
if is not specified, the default pins are 6 for latch, 7 for clock, and 5 for data.
displayType
(DisplayType): type of the display, can be common anode or common cathode.
displaySize
(int): quantity of digits on the display.
sectionSizes
(int[]): quantity of digits for each section, defined by each value in array;
end array with a 0 or lower value.
displayDrive
(DisplayDrive): drive algorithm of the display, can be multiplexed drive or static drive;
if is not specified, the default is MULTIPLEXED_DRIVE
.
swappedShiftRegisters
(bool): when set to true, changes shift registers order to first being digit index controller, and second being segment controller;
if is specified, displayDrive is forced to MULTIPLEXED_DRIVE
.
indexes
(int[]): custom digit index order, each array position contains the index of where the digit is output from the shift register;
if is not specified, the default is { 0, 1, 2, 3, 4, 5, 6, 7 }
.
set()
Encode and store a value for showing next on the display. The entire previous value is cleared.
display
(ShiftDisplay): object where function is called.
number
(int | long | float | double): numeric value to set;
if is too big to fit in the display, it is trimmed according to alignment.
text
(char | char[] | String): textual value to set;
valid characters are 0-9 a-z A-Z -
, other characters are converted to space;
char array must be null-terminated;
if is too big to fit in the display, it is trimmed according to alignment.
customs
(byte[]): custom characters to set, encoded in abcdefgp format, each byte is a character on the display, from left to right;
array length must match display size.
characters
(char[]): characters to set, each char is a character on the display, from left to right;
valid characters are 0-9 a-z A-Z -
, other characters are converted to a space;
array length must match display size.
dots
(bool[]): dot values to set, each bool is a dot on the display, from left to right;
true to show the dot, false to hide the dot;
array length must match display size.
decimalPlaces
(int): quantity of digits following the decimal point;
the value is rounded according to this;
if is set to 0, the decimal point will be removed;
if is not specified, the default is 1 for real numbers and 0 for integer numbers.
leadingZeros
(bool): show or hide zeros on the left of value;
if is not specified, the default is false.
alignment
(Alignment): alignment of the value on the display;
if is not specified, the default is ALIGN_RIGHT
for numbers and ALIGN_LEFT
for text.
changeDot()
Modify the stored value by adding or hiding a dot.
display
(ShiftDisplay): object where function is called.
index
(int): position on the display to change the dot, starting at 0 for the leftmost;
if is out of bounds, function does not have any effect.
dot
(bool): true to show the dot, false to hide the dot;
if is not specified, the default is true.
changeCharacter()
Modify the stored value by replacing the character (and dot) with a custom character.
display
(ShiftDisplay): object where function is called.
index
(int): position on the display to change the character, starting at 0 for the leftmost;
if is out of bounds, function does not have any effect.
custom
(byte): custom character to set, encoded in abcdefgp format.
setAt()
Encode and store a value for showing next on the specified section. The section previous value is cleared.
display
(ShiftDisplay): object where function is called.
section
(int): position of the section on the display to set the value, starting at 0 for the first;
if is out of bounds, function does not have any effect.
number
(int | long | float | double): numeric value to set;
if is too big to fit in the section, it is trimmed according to alignment.
text
(char | char[] | String): textual value to set;
valid characters are 0-9 a-z A-Z -
, other characters are converted to space;
char array must be null-terminated;
if is too big to fit in the section, it is trimmed according to alignment.
customs
(byte[]): custom characters to set, encoded in abcdefgp format, each byte is a character on the section, from left to right;
array length must match section size.
characters
(char[]): characters to set, each char is a character on the section, from left to right;
valid characters are 0-9 a-z A-Z -
, other characters are converted to a space;
array length must match section size.
dots
(bool[]): dot values to set, each bool is a dot on the section, from left to right;
true to show the dot, false to hide the dot;
array length must match section size.
decimalPlaces
(int): quantity of digits following the decimal point;
the value is rounded according to this;
if is set to 0, the decimal point will be removed;
if is not specified, the default is 1 for real numbers and 0 for integer numbers.
leadingZeros
(bool): show or hide zeros on the left of value;
if is not specified, the default is false.
alignment
(Alignment): alignment of the value on the section;
if is not specified, the default is ALIGN_RIGHT
for numbers and ALIGN_LEFT
for text.
changeDotAt()
Modify the stored value by adding or hiding a dot in a section.
display
(ShiftDisplay): object where function is called.
section
(int): position of the section on the display to change the dot, starting at 0 for the first;
if is out of bounds, function does not have any effect.
index
(int): position on the section to change the dot, starting at 0 for the leftmost;
if is out of bounds, function does not have any effect.
dot
(bool): true to show the dot, false to hide the dot;
if is not specified, the default is true.
changeCharacterAt()
Modify the stored value by replacing the character (and dot) with a custom character in a section.
display
(ShiftDisplay): object where function is called.
section
(int): position of the section on the display to change the character, starting at 0 for the first;
if is out of bounds, function does not have any effect.
index
(int): position on the section to change the character, starting at 0 for the leftmost;
if is out of bounds, function does not have any effect.
custom
(byte): custom character to set, encoded in abcdefgp format.
update()
Show on the display the stored value. For multiplexed drive, this must be called in a loop; for static drive, the value is shown until update()/clear()/show() is called.
display
(ShiftDisplay): object where function is called.
clear()
Hide the display content, without erasing stored value.
display
(ShiftDisplay): object where function is called.
show()
Show on the display the stored value, for the given time, then clear. Blocking function.
display
(ShiftDisplay): object where function is called.
time
(long): duration in milliseconds to show the value;
exact time showing will be an under approximation.
DisplayType: COMMON_ANODE
, COMMON_CATHODE
DisplayDrive: MULTIPLEXED_DRIVE
, STATIC_DRIVE
Alignment: ALIGN_LEFT
, ALIGN_RIGHT
, ALIGN_CENTER
TODO
TODO
TODO
TODO
TODO