7segment common cathode display with rtc

Ok, then I will try to help with the code. I agree you should only use 1 Arduino. It would be more difficult, and wasteful, to use 2 Arduino.

I think we should fix up the code you have now. It is very long and repetitive, and will be twice as long when we add downtime

@lingesh97

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

I would suggest using some arrays to hold the pin numbers:

//the pins of 4-digit 7-segment display attach to pin2-13 respectively
const byte segPin[2][8] = {
	//a,  b,  c,  d,  e,  f,  g, dp
	{ 2,  3,  4,  5,  6,  7,  8,  9}, //1st display
	{36, 34, 32, 30, 28, 26, 24, 22}  //2nd display
};
const byte digitPin[2][4] = {
	//1,  2,  3,  4
	{10, 11, 12, 13}, //1st display
	{44, 42, 40, 38}  //2nd display
};

const byte machine = 9;

they are at the other side sir

yes sir, i have tried adding downtime and its miserable with some errors...here what i have done

#include <TimerOne.h>

int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
int p = 9;
int A = 16;
int B = 17;
int C = 18;
int D = 19;
int E = 20;
int F = 21;
int G = 22;
int H = 23;
int P = 24;

int d4 = 10;
int d3 = 11;
int d2 = 12;
int d1 = 13;
int d8 = 25;
int d7 = 26;
int d6 = 27;
int d5 = 28;

int machineon = 30;
int machineoff = 31;

long n = 0;// n represents the value displayed on the LED display. For example, when n=0, 0000 is displayed. The maximum value is 9999.
long m = 0;
int x = 100;
int y = 100;

int del = 5;//Set del as 5; the value is the degree of fine tuning for the clock
int count = 0;//Set count=0. Here count is a count value that increases by 1 every 0.1 second, which means 1 second is counted when the value is 10
int count1 = 0;
int seconds=0,minutes=0,hours=0;
int second = 0, minute = 0, hour = 0;

void setup()
{
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(p, OUTPUT);
  pinMode(d5, OUTPUT);
  pinMode(d6, OUTPUT);
  pinMode(d7, OUTPUT);
  pinMode(d8, OUTPUT);
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(P, OUTPUT);
  
  Serial.begin(9600);
  Timer1.initialize(100000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  Timer1.attachInterrupt( add ); // attach the service routine here
}
void loop()
{
  runtime();
  downtime();
}
void runtime()
{
void display1()
{
  int digit_value_1;
  int digit_value_2;
  int digit_value_3;
  int digit_value_4; 
  if (digitalRead(machineon) == HIGH)
  {
    // 1. Load number 1

    digit_value_1 = seconds % 10;
    digit_value_2 = (seconds / 10) % 10;

    // 2. Load number 2

    digit_value_3 = (minutes) % 10;
    digit_value_4 = (minutes / 10) % 10;
    }

    //3. Update number to display
    pickDigit(0);//Light up 7-segment display d1
    pickNumber(digit_value_1);// get the value of thousand
    delay(del);//delay 5ms

    pickDigit(1);//Light up 7-segment display d2
    pickNumber(digit_value_2);// get the value of hundred
    delay(del);//delay 5ms

    pickDigit(2);//Light up 7-segment display d3
    pickNumber(digit_value_3);//get the value of ten
    delay(del);//delay 5ms

    pickDigit(3);//Light up 7-segment display d4
    pickNumber(digit_value_4);//Get the value of single digit
    delay(del);//delay 5ms

    delay(1);//loop delay update every 1 ms
}

void pickDigit(int x) //light up a 7-segment display
{
  switch(x)
  {
    case 0: 
        digitalWrite(d1, HIGH); digitalWrite(d2, LOW);digitalWrite(d3, LOW);digitalWrite(d4, LOW);
        break;
    case 1: 
        digitalWrite(d1, LOW); digitalWrite(d2, HIGH); digitalWrite(d3, LOW);digitalWrite(d4, LOW); 
        break;
    case 2:
        digitalWrite(d1, LOW);digitalWrite(d2, LOW); digitalWrite(d3, HIGH); digitalWrite(d4, LOW); 
        break;
      
    case 3:
        digitalWrite(d1, LOW);digitalWrite(d2, LOW);digitalWrite(d3, LOW);digitalWrite(d4, HIGH); 
        break;
    
    default: 
        digitalWrite(d1, LOW);digitalWrite(d2, LOW);digitalWrite(d3, LOW);digitalWrite(d4, LOW);  
        break;
  }
}

void pickNumber(int x)
{
  switch(x)
  {
     case 0: 
      zero(); 
      break;
    case 1: 
      one(); 
      break;
    case 2: 
      two(); 
      break;
    case 3: 
      three(); 
      break;
    case 4: 
      four(); 
      break;
    case 5: 
      five(); 
      break;
    case 6: 
      six(); 
      break;
    case 7: 
      seven(); 
      break;
    case 8: 
      eight(); 
      break;
    case 9: 
      nine(); 
      break;
    default: 
      zero(); 
      break;
  }
}


void clearLEDs() 
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(p, HIGH);
}

void zero() //display 0
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}

void one() //display 1
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);;
}

void two() //display 2
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
void three() //display 3
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void four() //display 4
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void five() //display 5
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void six() //display 6
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void seven() //display 7
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void eight() //display 8
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void nine() //display 9
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void add()
{
  if (digitalRead(machineon)==HIGH)
  {
  if (count < 10)
  {

    count ++;
  }

  else
  {
    count = 0;
    if (seconds < 59) seconds++;

    else
    {
      seconds = 0;
      if (minutes < 59)minutes++;

      else
      {
        minutes = 0;
        if (hours < 23)hours++;
        else hours = 0;
      }
    }
  }
  }
}
}
void downtime()
{
void display2()
{
  int digit_value_5;
  int digit_value_6;
  int digit_value_7;
  int digit_value_8; 
  if (digitalRead(machineoff) == HIGH)
  {
    // 1. Load number 1

    digit_value_5 = second % 10;
    digit_value_6 = (second / 10) % 10;

    // 2. Load number 2

    digit_value_7 = (minute) % 10;
    digit_value_8 = (minute / 10) % 10;
    }

    //3. Update number to display
    pickDigit1(0);//Light up 7-segment display d1
    pickNumber1(digit_value_5);// get the value of thousand
    delay(del);//delay 5ms

    pickDigit1(1);//Light up 7-segment display d2
    pickNumber1(digit_value_6);// get the value of hundred
    delay(del);//delay 5ms

    pickDigit1(2);//Light up 7-segment display d3
    pickNumber1(digit_value_7);//get the value of ten
    delay(del);//delay 5ms

    pickDigit1(3);//Light up 7-segment display d4
    pickNumber1(digit_value_8);//Get the value of single digit
    delay(del);//delay 5ms

    delay(1);//loop delay update every 1 ms
}
void pickDigit1(int y) //light up a 7-segment display
{
  switch(y)
  {
    case 0: 
        digitalWrite(d5, HIGH); digitalWrite(d6, LOW);digitalWrite(d7, LOW);digitalWrite(d8, LOW);
        break;
    case 1: 
        digitalWrite(d5, LOW); digitalWrite(d6, HIGH); digitalWrite(d7, LOW);digitalWrite(d8, LOW); 
        break;
    case 2:
        digitalWrite(d5, LOW);digitalWrite(d6, LOW); digitalWrite(d7, HIGH); digitalWrite(d8, LOW); 
        break;
      
    case 3:
        digitalWrite(d5, LOW);digitalWrite(d6, LOW);digitalWrite(d7, LOW);digitalWrite(d8, HIGH); 
        break;
    
    default: 
        digitalWrite(d5, LOW);digitalWrite(d6, LOW);digitalWrite(d7, LOW);digitalWrite(d8, LOW);  
        break;
  }
}
void pickNumber1(int y)
{
  switch(y)
  {
     case 0: 
      zeros(); 
      break;
    case 1: 
      ones(); 
      break;
    case 2: 
      twos(); 
      break;
    case 3: 
      threes(); 
      break;
    case 4: 
      fours(); 
      break;
    case 5: 
      fives(); 
      break;
    case 6: 
      sixs(); 
      break;
    case 7: 
      sevens(); 
      break;
    case 8: 
      eights(); 
      break;
    case 9: 
      nines(); 
      break;
    default: 
      zeros(); 
      break;
  }
}
void zeros() //display 0
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
}
void ones() //display 1
{
  digitalWrite(A, HIGH);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);;
}

void twos() //display 2
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, HIGH);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
}
void threes() //display 3
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
}

void fours() //display 4
{
  digitalWrite(A, HIGH);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
}

void fives() //display 5
{
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
}

void sixs() //display 6
{
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
}

void sevens() //display 7
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
}

void eights() //display 8
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
}

void nines()
{
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
}
void add1()
{
  if (digitalRead(machineoff)==HIGH)
  {
  if (count1 < 10)
  {

    count1 ++;
  }

  else
  {
    count1 = 0;
    if (second < 59) second++;

    else
    {
      second = 0;
      if (minute < 59)minute++;

      else
      {
        minute = 0;
        if (hour < 23)hour++;
        else hour = 0;
      }
    }
  }
  }
}
}


@lingesh97, this is the third cross-post and the second warning.

Do not cross-post again.

As I warned in reply #22, your code has now become very long, it is about 8 times longer than it needs to be. Longer code is harder to debug. Did you consider my suggestion from reply #24? You replied but seemed to ignore it. You did not ask any questions about it.

As mentioned in reply #6, you should use millis() for timing. Relying on use of delay() and incrementing counters will not be accurate.

should is use RTC ds1307 for this project?

hi, i have tried using millis()....as you said it is very accurate...but the problem im facing now is the millis() doesnt pause when there is no signal...what am i supposed to do?`

void add()
{
  if (digitalRead(machine)==HIGH)
  {
// I  think using microseconds is even more accurate
  if (millis() >= (previousTime)) 
  {
     previousTime = previousTime + 1000;  // use 100000 for uS
     seconds = seconds +1;
     if (seconds == 60)
     {
        seconds = 0;
        minutes = minutes +1;
     }
     if (minutes == 60)
     {
        minutes = 0;
        hours = hours +1;
     }
  }
  }
}

In fact, millis(), micros() and the timerOne library are all equally accurate. They have different precision.

I think any of them may be ok for your project. Your displays only show hours and minutes, so inaccuracies of less than a second won't be noticed, I think.

It can be done using millis() or micros(), even though it is not possible to pause those functions from updating. To do that, it would be necessary to use another variable to accumulate the previous total running time, and update that when the signal disappears. When the signal appears again, the current value off millis() or micros() can be recorded in a variable. Later, the total running time can be calculated using the current value of millis() or micros(), the time when the signal appeared, plus the total accumulated time.

But your current method using timerOne library can also be used. To update either the running time or the stopped time of the machine, you can simply check if the machine is running in the add() function, and updated either the running time or the stopped time.

int seconds[2], minutes[2], hours[2];

...

void add()
{
  byte i = 0;
  if (digitalRead(machine)==HIGH) i = 1;

  seconds[i] = seconds[i] +1;
   if (seconds[i] == 60)
   {
     seconds[i] = 0;
      minutes[i] = minutes[i] +1;
   }
   if (minutes[i] == 60)
   {
      minutes[i] = 0;
      hours[i] = hours[i] +1;
   }
  }
}

hi sir, i have tried your method and i couldnt get the output i wanted. i have to admit that my knowledge need to be improved on these microcontroller understanding. i would like to thank to everyone who helping me to improve..thanks for the time..

here is the programme i got what i wanted which is pause when there is no signal, the problem now is, its in milisecond and secs and i want it to display in seconds and minutes.

void add()
{
  millis() >= previousTime;
  if (digitalRead(machine)==HIGH)
  {
// I  think using microseconds is even more accurate
     previousTime = previousTime + 1000;
     seconds = seconds +1;
     if (seconds == 60)
     {
        seconds = 0;
        minutes = minutes +1;
     }
     if (minutes == 60)
     {
        minutes = 0;
        hours = hours +1;
     }
  
  }
}

Hi,

What did you get when running the code?

Tom..... :+1: :coffee: :australia:

1 Like

its supposed to display minutes and seconds, but mine displaying seconds and milliseconds

void add()
{
  if (digitalRead(machine)==HIGH)
  {
// I  think using microseconds is even more accurate
  if (millis() >= (previousTime)) 
  {
     previousTime = previousTime + 1000;  // use 100000 for uS
     seconds = seconds +1;
     if (seconds == 60)
     {
        seconds = 0;
        minutes = minutes +1;
     }
     if (minutes == 60)
     {
        minutes = 0;
        hours = hours +1;
     }
  }
  }
}

Hi,

Please appreciate that reply is very informative than .

To add code please click this link;

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

if i want to make this whole code for two for digit display, how it supposed to be?
my senior doesnt wants to multiplex it because he said it doesnt support the display board. Please help me, im really stucked.

#include <TimerOne.h>
//the pins of 4-digit 7-segment display attach to pin2-13 respectively
int a = 2;
int b = 3;
int c = 4;
int d = 5;
int e = 6;
int f = 7;
int g = 8;
int machine = 9;

int d4 = 10;
int d3 = 11;
int d2 = 12;
int d1 = 13;

int del = 5;//Set del as 5; the value is the degree of fine tuning for the clock
int count = 0;//Set count=0. Here count is a count value that increases by 1 every 0.1 second, which means 1 second is counted when the value is 10
int seconds = 0, minutes = 0, hours = 0;
unsigned long previousTime = 0;
unsigned long currentTime = 0;


void setup()
{
  pinMode(d1, OUTPUT);
  pinMode(d2, OUTPUT);
  pinMode(d3, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(machine, INPUT);


  Timer1.initialize(100000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  Timer1.attachInterrupt( add ); // attach the service routine here
}


void loop()
{
  int digit_value_1;
  int digit_value_2;
  int digit_value_3;
  int digit_value_4; 
  if (digitalRead(machine) == HIGH)
  {
    // 1. Load number 1

    digit_value_1 = (seconds/10) % 10;
    digit_value_2 = (seconds / 100) % 10;

    // 2. Load number 2

    digit_value_3 = (minutes/10) % 10;
    digit_value_4 = (minutes / 100) % 10;
    }

    //3. Update number to display
    pickDigit(0);//Light up 7-segment display d1
    pickNumber(digit_value_1);// get the value of thousand
    delay(del);//delay 5ms

    pickDigit(1);//Light up 7-segment display d2
    pickNumber(digit_value_2);// get the value of hundred
    delay(del);//delay 5ms

    pickDigit(2);//Light up 7-segment display d3
    pickNumber(digit_value_3);//get the value of ten
    delay(del);//delay 5ms

    pickDigit(3);//Light up 7-segment display d4
    pickNumber(digit_value_4);//Get the value of single digit
    delay(del);//delay 5ms

    delay(1);//loop delay update every 1 ms
}

void pickDigit(int x) //light up a 7-segment display
{
  switch (x)
  {
    case 0:
      digitalWrite(d1, HIGH); digitalWrite(d2, LOW); digitalWrite(d3, LOW); digitalWrite(d4, LOW);
      break;
    case 1:
      digitalWrite(d1, LOW); digitalWrite(d2, HIGH); digitalWrite(d3, LOW); digitalWrite(d4, LOW);
      break;
    case 2:
      digitalWrite(d1, LOW); digitalWrite(d2, LOW); digitalWrite(d3, HIGH); digitalWrite(d4, LOW);
      break;

    case 3:
      digitalWrite(d1, LOW); digitalWrite(d2, LOW); digitalWrite(d3, LOW); digitalWrite(d4, HIGH);
      break;

    default:
      digitalWrite(d1, LOW); digitalWrite(d2, LOW); digitalWrite(d3, LOW); digitalWrite(d4, LOW);
      break;
  }
}

void pickNumber(int x)
{
  switch (x)
  {
    case 0:
      zero();
      break;
    case 1:
      one();
      break;
    case 2:
      two();
      break;
    case 3:
      three();
      break;
    case 4:
      four();
      break;
    case 5:
      five();
      break;
    case 6:
      six();
      break;
    case 7:
      seven();
      break;
    case 8:
      eight();
      break;
    case 9:
      nine();
      break;
    default:
      zero();
      break;
  }
}

void clearLEDs()
{
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void zero() //display 0
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
}

void one() //display 1
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);;
}

void two() //display 2
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}
void three() //display 3
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
}

void four() //display 4
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void five() //display 5
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void six() //display 6
{
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void seven() //display 7
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}

void eight() //display 8
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void nine() //display 9
{
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}

void add()
{
  if (digitalRead(machine)==HIGH)
  {
// I  think using microseconds is even more accurate
  if (millis() >= (previousTime)) 
  {
     millis() == previousTime + 1000;  // use 100000 for uS
     seconds = seconds +1;
     if (seconds == 600)
     {
        seconds = 0;
        minutes = minutes +10;
     }
     if (minutes == 600)
     {
        minutes = 0;
        hours = hours +10;
     }
     if (hours ==240)
     {
      hours = 0;
     }
  }
  }
}