Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #60 on: December 30, 2010, 03:43:00 pm » |
I was going to say that it says crystal in the 'mouse-over'... anyway, yes, the exact same as the picture.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #61 on: December 30, 2010, 07:01:59 pm » |
Ok, moving on (at the minute) to the [glow]PAUSE[/glow] feature. I currently have a button that does this; if(buttonLap.isPressed()){ // pause and show lap time digitalWrite(latchpin, LOW); // send the digits down to the shift registers! shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit digitalWrite(latchpin, HIGH); delay([glow]15000[/glow]); hundredths = -1; tenths = 0; ones_seconds = [glow]5[/glow]; // 5 secs tens_seconds = [glow]1[/glow]; // 10 secs ones_minutes = 0; tens_minutes = 0;
} So basically, this pauses the display for 15 secs and then returns to the digits at 00:15:00. This works but is not what I want.. what I would like is to pause the time on the digits like above and do nothing untill the same button is pressed again then we can add the pause time to the display as if it had been counting in the background. I have been trying to look at the Do.. While.. or the HIGH/LOW but to be honest I don't know what I am looking for. Any tips or help would be greatly appreciated. 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #62 on: December 30, 2010, 08:59:34 pm » |
Oh no no no, not delay. Capture the time when the button is pressed, set a flag. Prior to shifting out the data see if the flag is cleared, and don't shift the data until time has passed and the flag is cleared.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #63 on: December 31, 2010, 03:33:31 pm » |
I don't know how to write that Robert?? :-[ I wouldn't know where to start.. where is the time.. in code? I assume I would make another flag; int time_update = 0;// added new flag int time_pause = 0;// paused time and I think the code would run down the incrementing to the last increment which should either print the segments as usual or goto a fixed print (pause) but not go back to the code until pressed again??? I can just about manage to put that in English never mind Arduino code.. Lol. :-/ Also I would have to add the time while paused to the next lap. Can you point me to any code that would have something like this or any hints on how to go about it.. pleeeeease...  PS> HAPPY NEW YEAR TO EVERYONE! 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #64 on: December 31, 2010, 05:31:37 pm » |
Rats! Had something all typed up, hit some key, wiped it all out. Anyway, you basically want something like like, so your time is still running, but display updating is bypassed. if (paused == 0){ // your shiftout code is in here
// after the shifouts, read the pause button, set a flag if pressed, capture the time it was pressed pause_button_state = digitalRead(pause_button); if (pause_button == 0){ paused = 1; start_pausetime = millis(); } }
// if paused, see for how long, if long enough clear the flag else { end_pausetime = millis(); elapsed_pausetime = end_pausetime - start_pausetime; // if (elapsed_pausetime >= pause_interval){ paused = 0; } }
of course, add the new variables, unsigned longs for the time related variables.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #65 on: December 31, 2010, 06:28:29 pm » |
Hi Robert.. maybe it's late or I've been looking at this code too much but my mind is going all blank to this.. I'm not sure how to place the code into my code?? I'm not sure what to initialise or exactly what to change.. do I change if (paused == 0){ to if (time_pause == 0){ I tried to change it for my code etc but obviously I did it wrong as it wouldn't even compile?? I will look at it again tomorrow and hopefully it will make more sense although any pointers to make it easier would be great. Ah well, off to bed now for some ZZZzzzzzzzzzzzzzz's and wake up tomorrow to start a whole new year! 8-)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #66 on: December 31, 2010, 08:25:58 pm » |
Happy New Year! I'm guessing you are tired: declare these byte pause_button_state = 0; byte pause_button = 6; byte paused = 0; unsigned long start_pausetime = 0; unsigned long end_pausetime = 0; unsigned long elapsed_pausetime = 0; unsigned long pause_interval= 0; setup up the input pin pinMode(pause_button, INPUT); digitalWrite (pause_button, HIGH); then add this towards the end of the file if (ones_hours == 13){ // I added hours; this is the last digit you check before shiftout ones_hours = 0; tens_hours = tens_hours +1; } if (paused == 0){
// your shiftout code is in here
// counters are all updated now, just do the shiftout one time here: digitalWrite(latchpin, LOW); // send the digits down to the shift registers! shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit digitalWrite(latchpin, HIGH);
// after the shifouts, read the pause button, set a flag if pressed, capture the time it was pressed pause_button_state = digitalRead(pause_button); if (pause_button == 0){ paused = 1; start_pausetime = millis(); } }
// if paused, see for how long, if long enough clear the flag else { end_pausetime = millis(); elapsed_pausetime = end_pausetime - start_pausetime; // if (elapsed_pausetime >= pause_interval){ paused = 0; } } } // end if time to be updated } // end void loop
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #67 on: January 01, 2011, 12:08:57 pm » |
Hi Robert.. yea I think I was tired, I had way too many late nights reading code!! Lol. Anyway, I put the code in where you said but it wont pause?? I will keep mucking with it to see if I can get it running. Looking at the code if I short pin 6 to ground it should pause.. :-/ is this correct? This is where I put everything; byte pause_button_state = 0; byte pause_button = 6; byte paused = 0;
unsigned long start_pausetime = 0; unsigned long end_pausetime = 0; unsigned long elapsed_pausetime = 0; unsigned long pause_interval= 0;
unsigned long currentmillis = 0; unsigned long previousmillis = 0; unsigned long interval = 10000; unsigned long elapsedmillis = 0;
byte latchpin = 8; // connect to pin 12 on the 74HC595 byte clockpin = 12; // connect to pin 11 on the 74HC595 byte datapin = 11; // connect to pin 14 on the 74HC595
byte ones_seconds = 0; byte tens_seconds = 0; byte ones_minutes = 0; byte tens_minutes = 0; byte tenths = 0; byte hundredths = 0; byte ones_hours = 0; byte tens_hours = 0;
int segdisp[10] = { 63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers //The above numbers light up different segments of a digit
int time_update = 0;// added new flag void setup() { pinMode(latchpin, OUTPUT); pinMode(clockpin, OUTPUT); pinMode(datapin, OUTPUT); pinMode(pause_button, INPUT); digitalWrite (pause_button, HIGH);
}
void loop() { currentmillis = micros(); // read the time. elapsedmillis = currentmillis - previousmillis;
if (elapsedmillis >= interval) // 10 milliseconds have gone by { previousmillis = previousmillis + elapsedmillis; // save the time for the next comparison time_update = 1; }
if (time_update == 1){ // no updating if not at 10ms interval, skip this whole section // increment the counters, roll as needed, shift the digits out
time_update = 0; // reset for next pass thru
hundredths = hundredths +1; if (hundredths == 10){ hundredths = 0; tenths = tenths +1; }
if (tenths == 10){ tenths = 0; ones_seconds = ones_seconds +1; }
if (ones_seconds == 10){ ones_seconds = 0; hundredths = hundredths +3; // Speed up the clock! tens_seconds = tens_seconds +1; }
if (tens_seconds == 6){ tens_seconds = 0; hundredths = hundredths +6; ones_minutes = ones_minutes +1; }
if (ones_minutes == 10){ ones_minutes = 0; tens_minutes = tens_minutes +1; } if (tens_minutes == 6){ tens_minutes = 0; ones_hours = ones_hours +1; }
if (ones_hours == 13){ // I added hours; this is the last digit you check before shiftout ones_hours = 0; tens_hours = tens_hours +1; } if (paused == 0){
// your shiftout code is in here
// counters are all updated now, just do the shiftout one time here: digitalWrite(latchpin, LOW); // send the digits down to the shift registers! shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit digitalWrite(latchpin, HIGH);
// after the shifouts, read the pause button, set a flag if pressed, capture the time it was pressed pause_button_state = digitalRead(pause_button); if (pause_button == 0){ paused = 1; start_pausetime = millis(); } }
// if paused, see for how long, if long enough clear the flag else { end_pausetime = millis(); elapsed_pausetime = end_pausetime - start_pausetime; // if (elapsed_pausetime >= pause_interval){ paused = 0; } } } // end if time to be updated } // end void loop
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #68 on: January 01, 2011, 12:42:32 pm » |
Hmm, yes I added some serial.prints where the shift outs, and I not seeing it pause either. I am out the door in 10 minutes for a fencing tournament, will look into this more when I get back. Not reading the pause button somehow.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #69 on: January 01, 2011, 12:57:18 pm » |
No worries Robert.. once again, really appreciated. Have fun at the fencing!! Don't get stabbed! Lol 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #70 on: January 01, 2011, 06:07:10 pm » |
Well, I blew the tournament, misread the schedule & got there 45 minutes late.
Finally figured the lack of pause:
pause_button_state = digitalRead(pause_button); if ([glow]pause_button [/glow]== 0){
we're looking at the wrong thing! This should be 'pause_button_state' Pauses okay now.
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #71 on: January 01, 2011, 06:20:44 pm » |
Hi Robert.. I tried that but no change?? I have highlighted where I made the change in the code below. I presume I am correct by grounding pin 6 on the Arduino? byte pause_button_state = 0; byte pause_button = 6; byte paused = 0;
unsigned long start_pausetime = 0; unsigned long end_pausetime = 0; unsigned long elapsed_pausetime = 0; unsigned long pause_interval= 0;
unsigned long currentmillis = 0; unsigned long previousmillis = 0; unsigned long interval = 10000; unsigned long elapsedmillis = 0;
byte latchpin = 8; // connect to pin 12 on the 74HC595 byte clockpin = 12; // connect to pin 11 on the 74HC595 byte datapin = 11; // connect to pin 14 on the 74HC595
byte ones_seconds = 0; byte tens_seconds = 0; byte ones_minutes = 0; byte tens_minutes = 0; byte tenths = 0; byte hundredths = 0; byte ones_hours = 0; byte tens_hours = 0;
int segdisp[10] = { 63,6,91,79,102,109,125,7,127,111 }; //segment references using 74HC595 Shift Registers //The above numbers light up different segments of a digit
int time_update = 0;// added new flag void setup() { pinMode(latchpin, OUTPUT); pinMode(clockpin, OUTPUT); pinMode(datapin, OUTPUT); pinMode(pause_button, INPUT); digitalWrite (pause_button, HIGH);
}
void loop() { currentmillis = micros(); // read the time. elapsedmillis = currentmillis - previousmillis;
if (elapsedmillis >= interval) // 10 milliseconds have gone by { previousmillis = previousmillis + elapsedmillis; // save the time for the next comparison time_update = 1; }
if (time_update == 1){ // no updating if not at 10ms interval, skip this whole section // increment the counters, roll as needed, shift the digits out
time_update = 0; // reset for next pass thru
hundredths = hundredths +1; if (hundredths == 10){ hundredths = 0; tenths = tenths +1; }
if (tenths == 10){ tenths = 0; ones_seconds = ones_seconds +1; }
if (ones_seconds == 10){ ones_seconds = 0; hundredths = hundredths +3; // Speed up the clock! tens_seconds = tens_seconds +1; }
if (tens_seconds == 6){ tens_seconds = 0; hundredths = hundredths +6; ones_minutes = ones_minutes +1; }
if (ones_minutes == 10){ ones_minutes = 0; tens_minutes = tens_minutes +1; } if (tens_minutes == 6){ tens_minutes = 0; ones_hours = ones_hours +1; }
if (ones_hours == 13){ // I added hours; this is the last digit you check before shiftout ones_hours = 0; tens_hours = tens_hours +1; } if (paused == 0){
// your shiftout code is in here
// counters are all updated now, just do the shiftout one time here: digitalWrite(latchpin, LOW); // send the digits down to the shift registers! shiftOut(datapin, clockpin, MSBFIRST, segdisp[hundredths]); // print the % first "hundredths" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tenths]); // print the tens of hundredths digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_seconds]); // print the % first "seconds" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_seconds]); // print the tens of seconds digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[ones_minutes]); // print the % first "minute" digit shiftOut(datapin, clockpin, MSBFIRST, segdisp[tens_minutes]); // print the tens of minutes digit digitalWrite(latchpin, HIGH);
// after the shifouts, read the pause button, set a flag if pressed, capture the time it was pressed pause_button_state = digitalRead(pause_button); if ([glow]pause_button_state[/glow] == 0){ paused = 1; start_pausetime = millis(); } }
// if paused, see for how long, if long enough clear the flag else { end_pausetime = millis(); elapsed_pausetime = end_pausetime - start_pausetime; // if (elapsed_pausetime >= pause_interval){ paused = 0; } } } // end if time to be updated } // end void loop
|
|
|
|
|
Logged
|
|
|
|
|
Northern Ireland
Offline
Jr. Member
Karma: 0
Posts: 83
Arduino Novice!
|
 |
« Reply #72 on: January 01, 2011, 06:25:10 pm » |
This is a stab in the dark but do we not have to output the pin 6 in the Void setup or something like that??
PS. sorry about your tournament.. that's a real bumber when that happens.. :-?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #73 on: January 01, 2011, 06:33:40 pm » |
Put a time in for how long you want to pause for:
unsigned long pause_interval= 0;
I put mine at 5000, pauses nice.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 249
Posts: 16540
Available for Design & Build services
|
 |
« Reply #74 on: January 01, 2011, 06:37:47 pm » |
I've been barely on time a couple of times due to traffic, but totally missing is a new one on me. Are you pausing okay now?
|
|
|
|
|
Logged
|
|
|
|
|
|