This is what I have now. Probably not the best way of making it but it works with the counting...
I tried to follow graynomad's advice but now this is what I have.
I want it to count slower (speed = 1000) when a button is pressed. I have tried to change the code so it would just change the delay to 1000 and also just made a copy of the whole loop more or less with a longer delay but nothing works.
Can somebody help how I can make it work?
*/
int latchpin3 = 8; // connect to pin 12 on the second'595
int clockpin3 = 12; // connect to pin 11 on the second'595
int datapin3 = 11; // connect to pin 14 on the second'595
int latchpin2 = 5; // connect to pin 12 on the minute'595
int clockpin2 = 7; // connect to pin 11 on the minute'595
int datapin2 = 6; // connect to pin 14 on the minute'595
int latchpin1 = 3; // connect to pin 12 on the hour'595
int clockpin1 = 9; // connect to pin 11 on the hour'595
int datapin1 = 4; // connect to pin 14 on the hour'595
float b = 0;
int c = 0;
float d = 0;
int e = 0;
int speed = 10; // used to control speed of counting
int segdisp[10] = {
63,6,91,79,102,109,125,7,127,111 };
void setup()
{
pinMode(latchpin1, OUTPUT);
pinMode(clockpin1, OUTPUT);
pinMode(datapin1, OUTPUT);
pinMode(latchpin2, OUTPUT);
pinMode(clockpin2, OUTPUT);
pinMode(datapin2, OUTPUT);
pinMode(latchpin3, OUTPUT);
pinMode(clockpin3, OUTPUT);
pinMode(datapin3, OUTPUT);
}
void loop()
{
for (int z=0; z<24; z++) // count to 24 hours
for (int x=0; x<60; x++) // count to 60 minutes
for (int y=0; y<60; y++) // count to 60 seconds
// Count
{
digitalWrite(latchpin1, LOW);
shiftOut(datapin1, clockpin1, MSBFIRST, 0); // clears the right display
shiftOut(datapin1, clockpin1, MSBFIRST, 0); // clears the left display
digitalWrite(latchpin2, LOW);
shiftOut(datapin2, clockpin2, MSBFIRST, 0); // clears the right display
shiftOut(datapin2, clockpin2, MSBFIRST, 0); // clears the left display
digitalWrite(latchpin3, LOW);
shiftOut(datapin3, clockpin3, MSBFIRST, 0); // clears the right display
shiftOut(datapin3, clockpin3, MSBFIRST, 0); // clears the left display
{
digitalWrite(latchpin1, HIGH);
if (z<10)
{
digitalWrite(latchpin1, LOW);
shiftOut(datapin1, clockpin1, MSBFIRST, segdisp[z]); // sends the digit down the serial path of hours
shiftOut(datapin1, clockpin1, MSBFIRST, 63); // sends the digit down the serial path of hours
digitalWrite(latchpin1, HIGH);
}
else if (z>=10)
{
d=z%10; // find the remainder of dividing z by 10, this will be the right-hand digit
c=int(d); // make it an integer, c is the right hand digit
b=z/10; // divide z by 10 - the whole number value will be the left-hand digit
e = int(b); // e is the left hand digit
digitalWrite(latchpin1, LOW); // send the digits down to the shift registers!
shiftOut(datapin1, clockpin1, MSBFIRST, segdisp[c]);
shiftOut(datapin1, clockpin1, MSBFIRST, segdisp[e]);
digitalWrite(latchpin1, HIGH);
}
}
if (x<10)
{
digitalWrite(latchpin2, LOW);
shiftOut(datapin2, clockpin2, MSBFIRST, segdisp[x]); // sends the digit down the serial path of minutes
shiftOut(datapin2, clockpin2, MSBFIRST, 63); // sends the digit down the serial path of minutes
digitalWrite(latchpin2, HIGH);
}
else if (x>=10)
{
d=x%10; // find the remainder of dividing x by 10, this will be the right-hand digit, minutes
c=int(d); // make it an integer, c is the right hand digit
b=x/10; // divide x by 10 - the whole number value will be the left-hand digit, minutes
e = int(b); // e is the left hand digit
digitalWrite(latchpin2, LOW); // send the digits down to the shift registers!
shiftOut(datapin2, clockpin2, MSBFIRST, segdisp[c]);
shiftOut(datapin2, clockpin2, MSBFIRST, segdisp[e]);
digitalWrite(latchpin2, HIGH);
}
digitalWrite(latchpin3, HIGH);
if (y<10)
{
digitalWrite(latchpin3, LOW);
shiftOut(datapin3, clockpin3, MSBFIRST, segdisp[y]); // sends the digit down the serial path
shiftOut(datapin3, clockpin3, MSBFIRST, 63); // sends the digit down the serial path
digitalWrite(latchpin3, HIGH);
}
else if (y>=10)
{
d=y%10; // find the remainder of dividing y by 10, this will be the right-hand digit
c=int(d); // make it an integer, c is the right hand digit
b=y/10; // divide y by 10 - the whole number value will be the left-hand digit
e = int(b); // e is the left hand digit
digitalWrite(latchpin3, LOW); // send the digits down to the shift registers!
shiftOut(datapin3, clockpin3, MSBFIRST, segdisp[c]);
shiftOut(datapin3, clockpin3, MSBFIRST, segdisp[e]);
digitalWrite(latchpin3, HIGH);
}
{
delay (speed);
}
}
}