Counter problems

Hi good day.

Could you help me with my code? Please.

I plan to show how long 5 machines have been on each one.
I am using the Arduino Mega2560.

I should receive 5 signals respectively, depending on the machine that is turned on, it must start counting the specified time, that is if machine 1 is on, it must show me the time that machine has been on on a display, I already have to show the hours and minutes , if it is the signal S1, or S2.

What I want is to show me, for example, how long the machine one has been on, and then if it receives the signal from machine 2, then that it also shows me how long it has been.

But I don't know how to simplify the counter because I don't want to have to start variables for each signal.

#include "SevSeg.h"

SevSeg sevseg;   //Instanciamos el object
//Inicia para maquina 1
int hora = 0;
int minuto = 0;
int segundo = 0;

//Inicia para maquina 2
int hora2 = 0;
int minuto2 = 0;
int segundo2 = 0;

unsigned long tiempo1 = 0;
unsigned long tiempo2 = 0;
long actual = 500000;
long actual2 = 500000;

int Paro;     // variable para la señal de Paro
int Paro2;     // variable para la señal de Paro2
int Reset;   // variable para la señal de RESET

void setup()
{
  pinMode(Paro, INPUT);
  pinMode(Paro2, INPUT);
  pinMode(Reset, INPUT);

  //Display 7seg izquierdo hrs min
  byte hardwareConfig = N_TRANSISTORS;  //Indica que es cátodo común con NPN
  byte numDigits = 6;
  byte digitPins[] = {13, 12, 11, 10, 9, 8}; //transistores
  byte segmentPins[] = {1, 2, 3, 4, 5, 6, 7}; //ABCDEFG
  bool resistorsOnSegments = true;     //true indica que resistencia esta en el pin de segmento
  bool updateWithDelays = false;       //Recomendado
  bool leadingZeros = true;            //true muestra ceros a izquierda
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
  sevseg.setBrightness(60);

}

void loop()
{
  un_seg (); //void un seg

  if ( millis()<1000) {
    sevseg.setNumber(actual, 6);
  }
  contador(); //void contador
  unsigned long mils = millis();
  if ((Paro == 1) && (Reset == 0)) //Maquina 1
  {
    actual = 510000 + (hora * 100) + (segundo);
    sevseg.setNumber(actual, 6);
  }
  if ((Paro2 == 1) && (Reset == 0)) //Maquina2
  {
    actual2 = 520000 + (hora2 * 100) + (segundo2);
    sevseg.setNumber(actual2, 6);
  }
  sevseg.refreshDisplay();

  Paro = digitalRead(26);
  Paro2 = digitalRead(27);
  Reset = digitalRead(28);
}

void un_seg()
{
  tiempo2 = (millis() / 1000);
  if (( tiempo1 != tiempo2 ) && (Paro == 1)) {
    tiempo1 = tiempo2;
    segundo++;
  }
  if (( tiempo1 != tiempo2 ) && (Paro2 == 1)) {
    tiempo1 = tiempo2;
    segundo2++;
  }
}

void contador() {
  //rutina segundos
  if (( segundo == 61 ) || ( segundo2 == 61 )) {
    segundo = 0;
    segundo++;

    segundo2 = 0;
    segundo2++;
  }

  if ( ( segundo == 60 ) || ( segundo2 == 60 ) ) {
    segundo = 0;
    minuto++;

    segundo2 = 0;
    minuto2++;
  }
 
  // Rutina para los minutos
  if ((minuto == 61 ) || (minuto2 == 61 )) {
    minuto = 0;
    minuto++;

    minuto2 = 0;
    minuto2++;
  }

  if ( ( minuto == 60 ) || ( minuto2 == 60 )) {
    minuto = 0;
    hora++;

    minuto2 = 0;
    hora2++;
  }

  // Rutina para las horas
  if (( hora == 25 ) || ( hora2 == 25 )) {
    hora = 0;
    hora++;

    hora2 = 0;
    hora2++;
  }

  if ( (hora == 24) || (Reset == 1) || (hora2 == 24) ) {
    hora = 0;
    minuto = 0;
    segundo = 0;
    actual = 500000;

    hora2 = 0;
    minuto2 = 0;
    segundo2 = 0;
    actual2 = 500000;
  }
}

I appreciate your help.

Take a close look at arrays. I guess that's what you're looking for.

I would like to help and I tried to apply Google Translate to the comments in your code with little success. But I do see a few problems.

First of all, does this sketch even do anything?

You initialize the pin numbers as integer, but they are all zero:

int Paro;     // variable para la señal de Paro
int Paro2;     // variable para la señal de Paro2
int Reset;   // variable para la señal de RESET

void setup()
{
  pinMode(Paro, INPUT);
  pinMode(Paro2, INPUT);
  pinMode(Reset, INPUT);

This code makes no sense. For this if statement to be true, you will have to wait as long as 49 days.

if ( millis()<1000) {
    sevseg.setNumber(actual, 6);
  }

Wait! I thought that Paro, Paro2 and Reset were the I/O pin labels in your setup?

  Paro = digitalRead(26);
  Paro2 = digitalRead(27);
  Reset = digitalRead(28);

Also, it is poor programming technique to name variables with a capitalized word like "Paro". It's readable and it compiles, but it is non-standard. Most programmers use camelCase as you did in your setup: "leadingZeros". See Naming Conventions - Programming Questions - Arduino Forum for an excellent description.

Again, a misuse of millis(). This makes no sense unless I am missing something?

tiempo2 = (millis() / 1000);

Also, it is a good practice to use unsigned long variables anytime you are working with millis().

Read [this](http://tiempo2 = (millis() / 1000):wink: for more info on millis(). In general you only need to read millis() into a variable once per loop iteration, then make all of your tests against that variable.