Hi! im trying to show the seconds when pressing the button. I'm using a 4x4 matrix keypad for the buttons and a 4digit ssd.
I know that this Time=(Hrs*100+Min); Display.setNumber(Time); shows the hrs and min on the 4 digit SSD but my aim is to show the seconds when pressing the button '0'
Is there any other "Time" variable for this? for me to show seconds?
#include <SevSeg.h>
SevSeg Display;
#include <Keypad.h>
//CLOCK
const unsigned long period = 1000;
const unsigned long led_period = 500;
unsigned long startMillis;
unsigned long led_startMillis;
unsigned long currentMillis;
unsigned long led_currentMillis;
const int hrs_btn = A0;
const int min_btn = A1;
const int ledPin = A2;
int Hrs = 1;
int Min = 2;
int Sec = 58;
int Time;
int time;
int ledState = LOW;
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
byte rowPins[ROWS] = {A3,A2,A1,A0}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {13,A5,A4}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
boolean blink = false;
boolean ledPin_state;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Sets the digital pin as output.
digitalWrite(ledPin, HIGH); // Turn the LED on.
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
kpd.addEventListener(keypadEvent); // Add an event listener for this keypad
//clock
pinMode(hrs_btn, INPUT_PULLUP);
pinMode(min_btn, INPUT_PULLUP);
byte numDigits = 4;
byte digitPins[] = {9,10,11,12}; //change depending on wire
byte segmentPins[] = {2,3,4,5,6,7,8};
bool resistorOnSegments = false;
byte updateWithDelays = false;
bool hardwareConfig = COMMON_CATHODE;
bool leadingZeroes = true;
bool disableDecPoint = true;
Display.begin(hardwareConfig,numDigits, digitPins, segmentPins, resistorOnSegments, updateWithDelays,leadingZeroes, disableDecPoint);
Display.setBrightness(100);
}
void loop(){
char key = kpd.getKey();
currentMillis = millis();
if(currentMillis - startMillis >= period)
{
Sec = Sec + 1;
startMillis = currentMillis;
}
led_currentMillis = millis();
if(led_currentMillis - led_startMillis >= led_period)
{
led_startMillis = led_currentMillis;
if(ledState==LOW)
{
ledState = HIGH;
if(digitalRead(hrs_btn) == LOW)
{
Hrs = Hrs +1;
}
if(digitalRead(min_btn)==LOW)
{
Min=Min+1;
Sec=0;
}
}
else
{
ledState=LOW;
}
digitalWrite(ledPin,ledState);
}
if(Sec==60)
{
Sec=0;
Min=Min+1;
}
if(Min==60)
{
Min=0;
Hrs=Hrs+1;
}
if(Hrs==13)
{
Hrs=1;
}
Time=(Hrs*100+Min);
Display.setNumber(Time);
Display.refreshDisplay();
}
// Taking care of some special events.
void keypadEvent(KeypadEvent key){
switch (kpd.getState()){
case PRESSED:
if (key == '0') {
}
if (key == '1') {
Min=Min+1;
}
if (key == '2') {
Hrs=Hrs+1;
}
break;
case RELEASED:
if (key == '*') {
// Restore LED state from before it started blinking.
blink = false;
}
break;
case HOLD:
if (key == '*') {
blink = true; // Blink the LED when holding the * key.
}
break;
}
}