#include "SevSeg.h"
const int ledPin = 2;
const int buttonPin = 27;
const int buzzerPin = 33;
SevSeg sevSeg;
int buttonState = LOW;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
int counter = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buzzerPin, OUTPUT);
byte numDigits = 1;
byte digitPins[] = {19};
byte segmentPins[] = {5, 4, 16, 17, 22, 0, 23, 18};
bool resistorsOnSegments = false;
byte hardwareConfig = COMMON_ANODE;
bool updateWithDelays = false;
bool leadingZeros = false;
bool disableDecPoint = false;
sevSeg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
sevSeg.setBrightness(100);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
counter++;
if(counter > 9) {
counter = 1;
}
sevSeg.setNumber(counter);
digitalWrite(ledPin, !digitalRead(ledPin));
tone(buzzerPin, 100);
delay(100);
noTone(buzzerPin);
}
}
}
sevSeg.refreshDisplay();
lastButtonState = reading;
}