#include <SevSegShift.h>
#include <DebouncedButton.h>
#define SHIFT_PIN_SHCP 2
#define SHIFT_PIN_STCP 3
#define SHIFT_PIN_DS 4
#define BUTTON_PIN 9
#define BUTTON_PIN2 8
#define BUTTON_PIN3 7
SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);
constexpr static bool PRESSED_STATE = true;
DebouncedButton button(PRESSED_STATE);
DebouncedButton button2(PRESSED_STATE);
DebouncedButton button3(PRESSED_STATE);
int numberToShow = 0;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(BUTTON_PIN2, INPUT_PULLUP);
pinMode(BUTTON_PIN3, INPUT_PULLUP);
byte numDigits = 3;
byte digitPins[] = {12,11,10}; // These are the PINS of the ** Arduino **
byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // 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 = true; // Use 'true' if you'd like to keep the leading zeros
bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
sevseg.setNumber(numberToShow);
}
int buttonState = 0;
void loop() {
auto now = millis();
auto input = button.update(digitalRead(BUTTON_PIN), now);
auto input2 = button2.update(digitalRead(BUTTON_PIN2), now);
auto input3 = button3.update(digitalRead(BUTTON_PIN3), now);
if (input == 6) {
numberToShow++;
}
if (input2 == 6) {
numberToShow--;
}
if (input3 == 6) {
numberToShow = 0;
}
//buttonState = digitalRead(BUTTON_PIN);
//if (buttonState == LOW) {
// numberToShow++;
// Serial.println("Pressed");
//}
sevseg.setNumber(numberToShow);
sevseg.refreshDisplay();
}