// Test if two seperated 7-segment displays can be controlled by the SevSeg library.
// The single-digit display is located on the left of the four-digit display.
//
// SevSeg library: https://github.com/DeanIsMe/SevSeg
// Using the stringWithPeriod.ino sketch as starting point:
// https://github.com/DeanIsMe/SevSeg/blob/master/examples/stringWithPeriod/stringWithPeriod.ino
//
//
// Both displays are "common anode".
//
#include <SevSeg.h>
SevSeg sevseg;
unsigned long previousMillis;
const unsigned long interval = 500;
unsigned long previousMillisFast;
const unsigned long intervalFast = 100;
void setup()
{
byte numDigits = 5;
byte digitPins[] = {6, 2, 3, 4, 5}; // single display, DIG1 ... DIG4
byte segmentPins[] = {7, 9, 11, 12, 13, 8, 10}; // a...g
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default. Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool noDecimalPoint = true; // No decimal point in this project
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, noDecimalPoint);
sevseg.setBrightness(100); // 100 is default, 0...200
}
void loop()
{
unsigned long currentMillis = millis();
bool update = false; // set default
static int xr;
int xm;
static int xlfast;
int xl;
static int y;
if( currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
// Two digits on the right, "xr"
// Count up
xr++;
if( xr > 99)
xr = 0;
update = true;
// One digit on the left, "xl"
// Count up slow
xlfast++;
xl = xlfast / 4;
if( xl > 9)
{
xlfast = 0;
xl = 0;
}
update = true;
// One digit on its own, "y"
// count up and down
static int inc = 1;
y += inc;
if( y == 9)
inc = -1;
if( y == 0)
inc = +1;
update = true;
}
if( currentMillis - previousMillisFast >= intervalFast)
{
previousMillisFast = currentMillis;
// One digit in the middle, "xm"
// set to random
xm = random(0,10);
update = true;
}
// Update the numbers if needed.
if( update)
{
char buffer[10];
snprintf( buffer, sizeof(buffer), "%1.1d%1.1d%1.1d%02.2d", y, xl, xm, xr);
sevseg.setChars( buffer);
update = false;
}
sevseg.refreshDisplay(); // This function keeps the displays going
}