Stopwatch with Pause/Lap  6 digit 7 seg LED. HELP!

It has been interesting developing this.
Not actually sure if the display pauses or not, stuff scrolls past pretty quick. That may need a little work still.

Hi Robert,
I saved the files you sent me and commented out (//) all the serial.print's. It compiled and uploaded to the Arduino no problem but still has the same problem as before. The start button starts the timer ok but does nothing else, (no pausing). The reset button reset's (after 1 second) and is working fine however when the memory up button is used it shows 54:32:10 followed by 17:98:76 followed by rubbish. No matter how I do this the read back result is the same every time even before making any saves?? (PS. The rubbish is the same too).
Each memory up click takes approx 2 to 2.5 seconds before the numbers show. :-/

Ok, so I reckon it is recalling some weird numbers because it isn't writing to memory or pausing and I think this would be fixed once it writes to memory??

On a positive note.. I got a delivery today of some extra large digits!! Beautiful 6 inch 7 segments. I have them all laid out on a piece of board and screwed down. Over the next few days I will be transferring from my old shift registers to my new ones.
I will start taking some photo's tomorrow and get them uploaded to let you see were I'm at.

Warren,
Try running it as I sent it, watching on the serial monitor. It was writing to the EEPROM and reading it back for me. I think - didn't try reading it back after power off, will try that next.
It was resetting the time and counting up from zero, like I said I wasn't sure if it was actually pausing the display.
Looks your memory read is displaying the address instead of the stored time:
54:32:10 is the address of the tens_minutes, ones_minutes, tens_seconds, ones_seconds, tenths, and then hundredths. 17:98:76 is similar.
I don't what you had in your memory before this.
I know when I read back after a reset, I get the times that were written in earlier.

Try running it as I sent it

Did that without any comments, then did it again (deleted everything) with everything commented just incase I did something wrong.

It was writing to the EEPROM and reading it back for me

Can't get it to do this??

like I said I wasn't sure if it was actually pausing the display

It's not pausing either.

It was resetting the time and counting up from zero

This is still ok.

I know when I read back after a reset, I get the times that were written in earlier.

Why would this give you the times and me the address?

I will get those pictures sorted later today,
Warren

I have to go clear the driveway from January snowstorm #3, then have a 2:00 appointment & need to hit the bank. Will look at this again this afternoon.
Oh, and just heard - January storm #4 expected for Wednesday!
About 15 years ago, the winter my son was born, we had 106" - wonder if this will be another like that?

we had 106"

Do you mean 106 inches of snow!? :o.. that's mad! Especially when you's had a baby on the way.. I hope you don't get it like that again although at 15 years of age.. it'd be good fun! Lol.

Anyway, here are a few pics of the large LED's I ordered.
I have them temporarily screwed to a piece of plywood just to see what they look like all together. I need to get a few nylon spacers to set them up on and I'm still waiting for my perspex to arrive. I am going to spray the base behind each of the segments in black paint so that it will absorb any light and not reflect back out.
In the meantime I need to sort my new shift registers and get them wired.




This is the type of finish I am hoping for;

Yep, 106 inches by the time winter was over. Luckily I had planned ahead and purhased a snow blower that fall.
This is my front yard, before Friday's storm. Snow is now piled up to the bottom of the mailbox.

I am having the hardest time getting the pause button to do 3 things - start time running after a new turn on or after stop/reset, pause the time, and then unpause the time. I keep running into the pause/unpause starting one after the other. What I see is the button press being acted upon multiple times; I'm working up a new method to have the next 'state' act on it (start, pause, unpause) and then not start the next state too early. Not quite there yet tho.

Those digits look monstrous when you get them together!

Hello Warren and Robert,
Warren - the Led's are amazings. Where are you buy it? :slight_smile:

Hi Robert, I hope that winter will end soon and everything will be OK. I hope then you will have not flooding. Because I am a volunteer fireman so I know something about it...

From my point of view is problem with pausing also. Debouncing of button and time between pushing mext lap has to be improoved. I tried reprogram routine with debouncing according basic scatch, but my skatchbook is again a little bit different, then yours... So I post here my routine with debouncing. lastReadings has to be taken also at start routine. Could you comment it? Thanks.

{  
  if (running == 1 &&(paused==0) &&((micros()-delayedReadings)>lastReadings))// It is no started so Start!
  {
    int reading_start1 = digitalRead (start_button);// reading_start is local variable
    if (reading_start1 != last_start_button_state)
    {
      // reset the debouncing timer
      lastDebounceTime_Pause = micros();
    }
    if ((micros() - lastDebounceTime_Pause) > debounceDelay) 
    {
      // whatever the reading is at, it's been there for longer
      // than the debounce delay, so take it as the actual current state:


      start_button_state = reading_start1;
    }
    // set the action of the button:

    last_start_button_state = reading_start1;
    if (start_button_state==LOW)
    {
      Serial.println("Should be paused");
      Serial.println(value);
      value++;
      copy_hundredths= hundredths;
      copy_tenths = tenths;
      copy_ones_seconds = ones_seconds;
      copy_tens_seconds = tens_seconds;
      copy_ones_minutes = ones_minutes;
      copy_tens_minutes = tens_minutes;
      Serial.print (copy_tens_minutes,DEC);
      Serial.print (copy_ones_minutes,DEC);
      Serial.print (":");
      Serial.print (copy_tens_seconds,DEC);
      Serial.print (copy_ones_seconds,DEC);
      Serial.print (":");
      Serial.print (copy_tenths,DEC);
      Serial.println (copy_hundredths,DEC);
      paused = 1;
      display_update = 1;
      EEPROM_writing = 1;// save the reading.  Next time through the loop,
      lastReadings=micros();
      delay(100);
    }
  }// End of LAP

}// End of reading Start button

Hi David,
It's just past mid January, we have another 2+months of snow to go!
The temperature is 10F (~-12, -14C) now, and its supposed to go to -10F tomorrow night - no melting going on any time soon :slight_smile:

I changed the code around some, making a memory_writing flag: 0 = no writing in process, 1 = memory writing in process, and 2 = memory writing done.
Then I put the memory writing code in it own tab, just like the memory reading code.
I put the code to read the pause button, debounce it, and control what function it did in its own tab, similar to what you had David, but with more functionality.
Doesn't work yet tho. When EEPROM writing is complete (EEPROM_writing == 2), the third part resets EEPROM_writing to 0 and then it seems to jump right back into another set of writes, so somehow it is seeing the button as having been pressed anew when it wasn't.

Well, adding the missing ='s didn't fix it, doesn't pause/write at all now...

// read the start button, 
start_button_state = digitalRead (start_button);
if (start_button_state == 0 ){
  press_time = millis();
  elapsed_presstime = press_time - old_presstime;
  if (elapsed_presstime >2000 && pause_pressed == 0)  
// meant to supply debounce time, and not currently doing any of the started actions
    pause_pressed = 1;
  Serial.println ("Start button pressed ");
  Serial.println ("Press allowed ");
  old_presstime = press_time;
}
else {
  pause_pressed = 0;
  press_state = 0;
}
// ********************************************************  
//If not running, set the running flag
if ((pause_pressed ==1) && (running == 0)){
  Serial.println ("New start!");
  running = 1;
  display_update = 1;
  press_state = 1; // starting time running
  pause_pressed = 0;
}

// ********************************************************
// Once running, see if should pause, etc.

// button read above
if ((pause_pressed == 1) && (press_state =[glow]=[/glow] 1) && (running == 1) && (EEPROM_writing == 0) ) {  // time running, 1000mS for debounce - [glow]just realized only had 1 = here too![/glow]  Serial.println ("Display paused, Time Reset, Time being Stored");
  display_update = 0;
  display_paused = 1;
  press_state = 2; // change to allow end of pause, with no new writing started

  // reset Time to 0
  currentmicros = micros();  // read the time.
  previousmicros = currentmicros;
  elapsedmicros = currentmicros - previousmicros;
  //MAKE COPIES
  copy_hundredths= hundredths;
  copy_tenths = tenths;
  copy_ones_seconds = ones_seconds;
  copy_tens_seconds = tens_seconds;
  copy_ones_minutes = ones_minutes;
  copy_tens_minutes = tens_minutes;
  EEPROM_writing = 1;
  Serial.println ("EEPROM writing enabled");

  // reset the time to 0
  hundredths = 0;
  tenths = 0;
  ones_seconds = 0;
  tens_seconds = 0;
  ones_minutes = 0;
  tens_minutes = 0;

  pause_pressed = 0; // done with all actions
}


// *************************************************************************
// if button was pressed & done writing, unpause to let time display be shown
if ((pause_pressed == 1) &&(press_state =[glow]=[/glow] 2) && (EEPROM_writing == 2)){
  //done writing, can let display updates start again - [glow]just realized only had 1 = here[/glow]  Serial.println ("Unpausing Display update");
  display_update = 1;
  display_paused = 0;
  display_paused_flag = 0;
  EEPROM_writing = 0;
  press_state = 1;  // writing is done, allow new pause to happen
  pause_pressed = 0;  // done with all actions

}

Warren, David,
I think I got it! Check out the updated files here:
http://www.crossroadsfencing.com/stopwatch_22Jan
/stopwatch_22Jan.pde
/a_presetup.pde
/b_setup.pde
/c_void_loop.pde
/d_start_pause_unpause
/e_memory_write
/f_memory_read
/g_stop_reset
/h_display_update

Uses Serialwrites still to show what is happening - if comment all out except those in h_display_write, the serial monitor should act like the shift register outputs.
Memory_up button has no effect after start/pause/unpause is pressed, can only read back on initial power-on, or after stop/reset button is pressed.
There are some writes in void_loop also, so can see 1S time increments while the display is paused as a sanity check.

Robert

Just found if you power up, do a couple of reads, then start, the first writes do not start from address 0; need to press reset first.

Hi Robert, so basicaly we have still trouble with start/pause button. :slight_smile: I went to begin again and I reworked basic structure for start button. From my point of view there was mistake at skeleton... Here is new one skeleton:

int start_button = 6;         // the number of the input pin
int outPin = 13;       // the number of the output pin

int start_button_counter = 1;       // how many times we have seen new value
int start_reading;           // the current value read from the input pin
int start_button_state = LOW;    // the debounced input value

int Value=0;

// the following variable is a long because the time, measured in milliseconds,
// will quickly become a bigger number than can be stored in an int.
long last_start_time = 0;         // the last time the output pin was sampled
long delayed_pause=5000;// How many miliseconds will be between pase time?
long current_running_time; // Variable for counting actual running time
int start_button_debounce_count = 10; // number of millis/samples to consider before declaring a debounced input

byte running = 0; // was 'started' 


void setup()
{
  Serial.begin(115200);
  pinMode(start_button, INPUT);
  digitalWrite (start_button, HIGH); // enable pullup
  pinMode(outPin, OUTPUT);
  digitalWrite(outPin, start_button_state); // setup the Output LED for initial state
}

void loop()
{
  //Start button begin here

  if(millis() != last_start_time)
  {
    start_reading = digitalRead(start_button);

    if(start_reading == start_button_state && start_button_counter > 0)
    {
      start_button_counter--;
    }
    if(start_reading != start_button_state)
    {
      start_button_counter++; 
    }
    // If the Input has shown the same value for long enough let's switch it
    if(start_button_counter >= start_button_debounce_count)
    {
      start_button_counter = 0;
      start_button_state = start_reading;
      digitalWrite(outPin, start_button_state);// Show state on LED at pin 13
      if (start_button_state==0)
      {
        switch (running)
        { 
        case 0: // Stopwatch are stopped, so we can run 
          //Start routine for changes here
          running = 1; 
          Serial.println ("Time running from 0");
          Serial.println (last_start_time);
          // End of start routine changes here 
         
          break; 
        case 1: // Stopwatch running, so we will pause it 
          current_running_time=millis()-last_start_time;
          Serial.println ("Time paused");
          Serial.print ("Actual millis:"); Serial.println (millis());
          Serial.print ("Button start was pressed at last time:");Serial.println (last_start_time);
          Serial.print ("So actually was not touched for:");Serial.println (current_running_time);
          if (current_running_time >= delayed_pause)
          {
            //Pause routines for changes here

              running = 1; 
            Serial.println ("Time paused and I am inside");
            Value++;
           Serial.print ("Here is stored time for next reading:"); Serial.println (last_start_time);

            Write_memory();


            // End of Pause routines here
          }
          break; 

        } // End of switch

      }

      last_start_time = millis();
    }
  }
  // Routine for Start button finish here




  //Routine for reset stopwatch here
  {

  }

  // Routine for memory read here
  {

  }


  //Routine for counting
  {

  }
}// End of loop

void Write_memory()
{
  // Here will be routines for memory write 
  Serial.println ("Here will be memory written");

}

What do you think about it?

Oups, I see, that I am so slowly. ;D
I will try new code from you Robert

The snow you get is crazy!! This country comes to a halt with 2 inches.. haha. Best of luck with it Robert and keep safe! :slight_smile:

The digits are BIG.. but I'd rather they were big than maybe not big enough!? The thing is, they need to be read at fast speeds so I am hoping the size is perfect.

Warren - the Led's are amazings. Where are you buy it?

Hi David, I got them from http://proto-pic.co.uk/products/7%252dSegment-Red-6.5"-Display.html in the UK.
They originally come from Sparkfun here: 7-Segment Display - 6.5" (Red) - COM-08530 - SparkFun Electronics
For what you get, they are very cheap and surprisingly good quality, I was really pleased. :slight_smile:

Robert, I tried your download link again but got a blank page again.
I was just wondering if you still had the old sketch from when it paused perfectly.. so you could compare as to why it's now not working. If you need it I keep copies of all the stages we have been going through.
Warren

Just realised that the code is also in this forum ::)..

Hi Warren, files are on places, where Robert wrote. You have to change text to rows by Enter keys after each semicolon, braces etc... Here are only fragments of all code!
So look at this:
http://www.crossroadsfencing.com/stopwatch_22Jan/stopwatch_22Jan.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/a_presetup.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/b_setup.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/c_void_loop.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/d_start_pause_unpause.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/e_memory_write.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/f_memory_read.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/g_stop_reset.pde
http://www.crossroadsfencing.com/stopwatch_22Jan/h_display_update.pde

Warren,
I put it up now as
http://www.crossroadsfencing.com/stopwatch_22Jan.zip
You should be able to download, unzip, and have a complete set of files now.

David,
I think the new skeleton agress with I ended up with. I just didn't write it as functions.
The main thing we started with was accurate 0.01 second intervals, the button pushes were incidental to that.
If you take the stuff in tabs and copy them all end to end, it looks like what you have.

I found as the programs get bigger, it just gets harder & harder to keep track of what is going on with all the scrolling up & down.

I wonder if the new forum, which we get moved to tomorrow, will allow for bigger code listings?
Seems to me thats its the comments which drive up the message size (limit of 9500 characters), yet without them code is pretty difficult to follow.

Robert

Warren,
I don't think display speed will be a problem. Electricity moves fast! And you are only switching 20mA. If you read the datasheet, time is not mentioned anywhere. The 100's will be a blur, you may be able to make out the tenth' as they change at 10 times a second.

What have you ended up with for a power source?

I don't think display speed will be a problem. Electricity moves fast! And you are only switching 20mA. If you read the datasheet, time is not mentioned anywhere. The 100's will be a blur, you may be able to make out the tenth' as they change at 10 times a second.

Display speed wont be a problem.. when I said "they need to be read at fast speeds" I was referring to the digit size as they will be in pause mode when being read by the rider/driver.

What have you ended up with for a power source?

I haven't sourced one yet.. I am going to use a power drill battery like you suggested before until I can find a good one. I want something slim so I can place it in the middle of the unit and try to keep everything balanced. :slight_smile:
I am going to download your zip now and report back shortly. :slight_smile:

That link isn't working..?? Taking me to "Page Not Found"??? :-/