Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #135 on: January 18, 2011, 04:04:15 pm » |
Problem with 'No Pause'?? byte paused = 0; doesn't seem to be being used? New Code; // read the pause button; unpause to let time display be shown start_button_state = digitalRead(start_button); if (start_button_state == 0 && EEPROM_writing == 0){ //done writing, can let display updates start again display_update = 1; }
Old Code; // read the pause button, set a flag if pressed, capture the time it was pressed, reset the lap time end_pausetime = millis(); if (paused == 0 & (end_pausetime - start_pausetime > 500)){ // not paused, debounced if had been (long time used due to crappy button) pause_button_state = digitalRead(pause_button); //PAUSED HERE if (pause_button_state == 0){ [glow]paused = 1;[/glow] start_pausetime = end_pausetime; Hope this helps.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #136 on: January 18, 2011, 08:08:42 pm » |
I changed paused to running, made it clearer in my mind. Might have missed it in a place or two. Then time update can be running, and display updating can be paused.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #137 on: January 20, 2011, 02:47:55 pm » |
Warren, David, I think I got it working now. Warren, I sent it to as a series of files that are the tabs. Set serial port speed to 57600, 9600 really slows time down :-) You have to press 'Reset' (button on D2) to stop before you can start reading back. There are a lot of extra serial.prints so I could monitor what was happenining (not having any hardware attached), you can start commenting those out if you think this is working correctly. 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. David, I cannot post it here, it got too big. The files are here if you want to download them (or will be in a few minutes, am FTPing now). Or PM me, I can e-mail them also. http://www.crossroadsfencing.com/stopwatch_20Jan/stopwatch_20Jan.pde /a_presetup.pde /b_setup.pde /c_void_loop.pde /d_start_stop.pde /e_pause_memory_write.pde /f_memory_read.pde /g_reset.pde /h_display_update.pde I ran it for 30 seconds, doing a time capture ~5 seconds, then letting it run ~10, then ~15, then ~22 or so (remembering that it resets to 0 every time). If you see 255 coming back, that is reading from an unwritten memory location. If time seems to be running slow, comment out the serial print lines, they are mostly only there for debugging anyways, the actual hardware will be an arduino, shift registers, and displays.
|
|
|
|
« Last Edit: January 20, 2011, 02:53:58 pm by CrossRoads »
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #138 on: January 20, 2011, 05:23:11 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #139 on: January 20, 2011, 11:26:20 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #140 on: January 21, 2011, 07:44:40 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #141 on: January 21, 2011, 11:47:46 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #142 on: January 22, 2011, 03:02:40 pm » |
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.    
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #143 on: January 22, 2011, 03:07:44 pm » |
This is the type of finish I am hoping for; 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #144 on: January 22, 2011, 07:29:26 pm » |
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!
|
|
|
|
« Last Edit: January 22, 2011, 07:32:27 pm by CrossRoads »
|
Logged
|
|
|
|
|
Opava,Czech Republic
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #145 on: January 23, 2011, 12:35:24 am » |
Hello Warren and Robert, Warren - the Led's are amazings. Where are you buy it?  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
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #146 on: January 23, 2011, 01:10:47 am » |
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 :-) 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
}
|
|
|
|
« Last Edit: January 23, 2011, 01:26:07 am by CrossRoads »
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #147 on: January 23, 2011, 02:59:30 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 247
Posts: 16535
Available for Design & Build services
|
 |
« Reply #148 on: January 23, 2011, 03:07:25 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Opava,Czech Republic
Offline
Newbie
Karma: 0
Posts: 19
Arduino rocks
|
 |
« Reply #149 on: January 23, 2011, 03:56:19 am » |
Hi Robert, so basicaly we have still trouble with start/pause button.  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?
|
|
|
|
|
Logged
|
|
|
|
|
|