HELP WANTED... PLEASE..
I am attempting to put together a simple 6 digit 7 seg-LED Stop Watch using 74HC595 Shift Registers x 6 (1 for each 7 seg).
I have hacked the following code from ... somewhere?? on the internet after searching everywhere without success for even any kind of 3 digit timer that I can maybe hack and adapt.
This code will light up 4 digits but only use the 2 on the right to count up to 59.. I can get it to count to 99 but I have it set to 59. :
When I tried to get it to count higher, like 2000+ it did it fine but didn't show correctly in the middle digit/s.
I know this is probably the wrong way to go about a timer/stopwach but I have been searching for weeks/days and this is the best I have got. :-/
Project idea is to eventually build a large 6" x 6 digit LED display for motor racing controlled initially by a hand button and in the future I want it to be triggered by a remote signal as the bike/car passes.
When the button is pressed I want it to pause the current time on the display while automatically restarting in the background timing the second lap. When the button is pressed again the display would show the current lap time..i.e, 'lap 2'.
Memory would also be neat but not essential at the minute.
I am using Arduino Uno with 74HC595 Shift Registers x 6 and single LED 7-segment CC.
Any help or pointers in the right direction would be really well appreciated. Many thanks in advance, Warren
int latchpin = 8; // connect to pin 12 on the 74HC595
int clockpin = 12; // connect to pin 11 on the 74HC595
int datapin = 11; // connect to pin 14 on the 74HC595
float b = 0;
int c = 0;
float d = 0;
int e = 0;
float f = 0;
int g = 0;
float h = 0;
int i = 0;
int speed = 100; // used to control speed of counting
int segdisp[10] = {
63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers
void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
}
void loop()
{
// Counts up to 59 only!
for (int z=0; z<59; z++)
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the left display
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the left display
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the left display
shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the left display
digitalWrite(latchpin, HIGH);
if (z<1)
{
digitalWrite(latchpin, LOW);
//****************************************************************************************************//
// I have left the following 2 lines as they were although I found no diference if I removed them?? **//
//****************************************************************************************************//
shiftOut(datapin, clockpin, MSBFIRST, segdisp[z]); // sends the digit down the serial path
shiftOut(datapin, clockpin, MSBFIRST, 0); // sends a blank down the serial path to push the digit to the right
digitalWrite(latchpin, HIGH);
}
else if (z>=1)
{
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
f=z/100; // divide z by 100 -
g = int(f); //
h=z/1000; // divide z by 1000 -
i = int(h); //
digitalWrite(latchpin, LOW); // send the digits down to the shift registers!
shiftOut(datapin, clockpin, MSBFIRST, segdisp[c]);
shiftOut(datapin, clockpin, MSBFIRST, segdisp[e]);
shiftOut(datapin, clockpin, MSBFIRST, segdisp[g]);
shiftOut(datapin, clockpin, MSBFIRST, segdisp[i]);
digitalWrite(latchpin, HIGH);
}
delay(speed);
}}