#include <Button.h>// need to stop debounce when i start using buttons but is there a naming convetion i need to follow...?
#include <SevSeg.h>// note am using the wokwi simulator site to run the code.
SevSeg sevseg; //Instantiate a seven segment controller object
//button designations
const int Start100 = A0; //set Seconds for 100
const int Start50 = A1; //set Seconds for 50
const int Start10 = A2; //set Seconds for 10
const int Runinfinty =A3; //to run main loop with out stopping count to 100 then start again as per orgininal program before i destroyed it.
//state of change not sure if i need these to check for which button is checked
int State100 =0;
int ChngeState100 =0;
int State50 = 0;
int ChngeState50 =0;
int State10 =0;
int changeState10 =0;
//relay on pin 13 to activate for 500 milli after every second/count
const int RelayAction = 13;// using an LED to simulate the relay
int Seconds=0;
int lastSeconds=0;
void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
bool updateWithDelays = false; // Default. Recommended
bool leadingZeros = true; // Use 'true' if you'd like to keep the leading zeros
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
sevseg.setBrightness(90);
pinMode(Start100, INPUT_PULLUP);
pinMode(Start50, INPUT_PULLUP);
pinMode(Start10, INPUT_PULLUP);
pinMode(RelayAction, OUTPUT);
}
void loop() {// unsure how to add in the button functions, or the raly activation function.
static unsigned long timer = millis();
static int Seconds = 0;
if (millis() - timer >= 2000) {// will be changed to 10000
timer += 2000;
Seconds++; // 1000 milliSeconds is equal to 1 Second
if (Seconds != lastSeconds) {//to activate the relay after every increment
digitalWrite (RelayAction, HIGH);
delay(500);// need a 500 wait here, delay is causing display issues.
digitalWrite(RelayAction, LOW);// working now.
}
if (Seconds == 11) { // Reset to 0 after counting for required count, value will be changed by button input
Seconds=0;
}
sevseg.setNumber(Seconds, 1);
}
sevseg.refreshDisplay(); // will need to change depending on button press
}