/* SevSegShift Counter Example
Copyright 2020 Dean Reading,
Copyright 2020 Jens Breidenstein
This example demonstrates a very simple use of the SevSegShift library with a 4
digit display. It displays a counter that counts up, showing deci-seconds.
https://github.com/bridystone/SevSegShift/tree/ShiftRegister/examples/SevSegShiftOne_Counter
*/
#include "SevSegShift.h"
#define SHIFT_PIN_SHCP 15
#define SHIFT_PIN_STCP 18
#define SHIFT_PIN_DS 23
//unsigned long startTime = millis();
//unsigned long stopTime = millis();
//unsigned long millisElapsed;
//unsigned long stoppedTime = 0;
unsigned long runningTime = 0;
unsigned long pressTime = 0;
unsigned long timeNow = 0;
unsigned long timeLast;
bool running = false;
bool stateChange = false;
int debounceTime = -100; // in milliseconds
/* Instantiate a seven segment controller object with:
- segment pins controlled via 1 shift register and
- digit pins connected to the Arduino directly
*/
SevSegShift sevsegshift(
SHIFT_PIN_DS,
SHIFT_PIN_SHCP,
SHIFT_PIN_STCP,
1, /* number of shift registers there is only 1 Shiftregister
used for all Segments (digits are on Controller)
default value = 2 (see SevSegShift example)
*/
true /* Digits are connected to Arduino directly
default value = false (see SevSegShift example)
*/
);
void setup() {
byte numDigits = 4;
byte digitPins[] = {4, 19, 21, 22}; // These are the PINS of the ** Arduino **
byte segmentPins[] = {0, 2, 4, 6, 7, 1, 3, 5}; // these are the PINs of the ** Shift register **
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
sevsegshift.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevsegshift.setBrightness(90);
pinMode(2, INPUT_PULLUP);
//Serial.begin(115200);
}
void loop() {
timeLast = timeNow;
timeNow = millis();
if ( ( pressTime - timeNow ) < debounceTime) {
if ( digitalRead(13) == LOW ) // ( pressTime - timeNow ) < debounceTime ) {
{
stateChange = true;
//Serial.println("stateChange");
if ( running == true ) {
running = false ;
} else {
running = true ;
}
pressTime = timeNow;
} else {
stateChange = false;
}
}
if ( running == true )
{
runningTime += ( timeNow - timeLast );
}
if ( runningTime >= 100000 ) {
runningTime = 0;
}
sevsegshift.setNumber((runningTime / 10), 2);
sevsegshift.refreshDisplay(); // Must run repeatedly
//Serial.println(pressTime);
delay(1);
}
/// END ///