part 3
h = (int)((elapsedTime / 10000L) % 10L); // get number of deca-seconds (10)
i = (int)((elapsedTime / 1000L) % 10L); // get number of seconds (1)
j = (int)((elapsedTime / 100L) % 10L); // get number of deci seconds (0,1)
k = (int)((elapsedTime / 10L) % 10L); // get number of centi seconds (0,01)
l = (int)(elapsedTime % 10L); // get number of milli seconds (0,001)
if ((int)(elapsedTime /60000) < 1) // if time < 1 minute show as 12.345
{
digitalWrite(latchPin, LOW); // enable writing to display
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[h]); // write deca seconds to first diplay
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[i]); // write seconds + decimal point to seconds display
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[j]); // write deci seconds to third display
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[k]); // write centi seconds to fourth display
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[l]); // write millie seconds to fifth display
digitalWrite(latchPin, HIGH); // stop writing to display
}
if ((int)(elapsedTime /60000) >= 1 && (int)(elapsedTime /60000) < 10 ) //if time > 1 minute but < 10 minutes show as 1.23.45
{
m = (int)(elapsedTime / 60000);
n = (int)((elapsedTime - (m*60000)) / 10000L);
o = (int)(((elapsedTime - (m*60000)) / 1000L) % 10L);
digitalWrite(latchPin, LOW); // enable writing to display
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[m]); //
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[n]); //
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[i]); //
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[j]);
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[k]);
digitalWrite(latchPin, HIGH); // stop writing to display
}
// to do
// if ((int)(lastlap /60000) >= 10) //if time > 10 minutes show as 12.34.5
digitalWrite(ledPin, LOW); // Turn blinking LED off
digitalWrite(delayPin, HIGH); // Turn delay LED on
delay(2000); // 2 second delay to close the beam
digitalWrite(delayPin, LOW); // Turn delay LED off
}
else{
lastButtonState = buttonState; // store buttonState in lastButtonState, to compare next time
}
// blink routine - blink the LED while timing
// check to see if it's time to blink the LED; that is, is the difference
// between the current time and last time we blinked the LED bigger than
// the interval at which we want to blink the LED.
if ( (millis() - previousMillis > interval) ) {
if (blinking == true && delaybuttonState != true && lastlapState != true) // If time is running start blinking and keep updating display
{
elapsedTime = millis() - startTime; // store elapsed time
h = (int)((elapsedTime / 10000L) % 10L); // get number of deca seconds
i = (int)((elapsedTime / 1000L) % 10L); // get number of seconds
if ((int)(elapsedTime /60000) < 1) // if time < 1 minute show as 12.345
{
digitalWrite(latchPin, LOW); // enable writing to display
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[h]); // write deca seconds to first diplay
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[i]); // write seconds + decimal point to seconds display
shiftOut(dataPin, clockPin, LSBFIRST, B0); // keep other three displays empty
shiftOut(dataPin, clockPin, LSBFIRST, B0);
shiftOut(dataPin, clockPin, LSBFIRST, B0);
digitalWrite(latchPin, HIGH); // stop writing to display
}
if ((int)(elapsedTime /60000) >= 1 && (int)(elapsedTime /60000) < 10 ) //if time > 1 minute but < 10 minutes show as 1.23.45
{
m = (int)(elapsedTime / 60000);
n = (int)((elapsedTime - (m*60000)) / 10000L);
o = (int)(((elapsedTime - (m*60000)) / 1000L) % 10L);
digitalWrite(latchPin, LOW); // enable writing to display
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[m]); //
shiftOut(dataPin, clockPin, LSBFIRST, cijfer[n]); //
shiftOut(dataPin, clockPin, LSBFIRST, cijfertwee[i]); //
shiftOut(dataPin, clockPin, LSBFIRST, B0);
shiftOut(dataPin, clockPin, LSBFIRST, B0);
digitalWrite(latchPin, HIGH); // stop writing to display
}
digitalWrite(delayPin, LOW); // turn off delay pin (it should be off but just in case
previousMillis = millis(); // remember the last time we blinked the LED
if (value == LOW) // if the LED is off turn it on and vice-versa.
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
}
else{
digitalWrite(ledPin, LOW); // turn off LED when not blinking so when it stops blinking in on-state it is turned off
}
}
}
}
}
/* todo
* - flipswitch for switching between laptime and total time in continous mode
*/
// end of program
(good to post my code because I think I found the reason of one of my bugs by reading the entire code over)
In very short:
- check is reset button is pressed, IF SO, stop time or set display to zero
- check if last lap button is pressed, IF SO, show last lap on display, keep time running
- check if delay button is closed, IF SO, don't do anything when beam is broken
- IF delay NOT pressed, check for braking beam, start/stop time or end a lap and start a new lap instant (according to position of flipswitch)
- when time is running, blink LED and keep updating display (only whole seconds)
- end program
code still in development same as the hardware since we found out soms functions/buttons were missing or could be adjusted. I use some dutch words in ther (ronde=lap, cijfer=number)(etc) but they are explained in the comments mostly so it should be readable
(hope I copied all the lines ;))
enjoy