if (meet == LOW){ delay(100); // delay between sound and flash digitalWrite(flashPin, HIGH); // flash goes off digitalWrite(flashPin, LOW); digitalWrite(ledPin, HIGH); // LED during 'dead time' delay(4000); //to make sure I only get one flash digitalWrite(ledPin, LOW); }
Not the first, but always nice to show some results Long exposures in dark room and triggered the flash on sound.
Used piezo for sound detection as in the trigger kit from the hiviz.com website. Hooked it up to my arduino to be abled to set the delay end reset time as I prefered. SCR to shortcut flash. Simple yet effective project.
Playing with different set-ups and delays (time between hard sound and flash trigger). Some results:
well, I did read that line but did not think any in the code would be wrong. Then I understand your thinking. But maybe it is not the best place to give exercises on an example site Since starting programmers will copy full examples to see if and how everything works so when their display does not equal their serial print they might search the fault sooner in their wiring or self written lines they added to the code than in the example code.
Off course one should not make it to easy for their students as well
The last zero however is not really needed since an intiger can off course be equal to zero so then the last 0 will be displayed and you only have to manually add the 2 zero's before 8-) now you will get one 0 to much, no problem since the value stays the same... but looks not as neat
since i use a small part off the stopwatch example on the arduino site I found out it has a minor bug, with the possibillity of giving a wrong time through the serial port. Since one cannot react on the examples, maybe smart to post it here (maybe they will change it), at least other users might read it. (if it is at the wrong place please move)
The problem is the way they divide the time into a part before the decimal point (whole seconds) and the fractional part.
Code:
Serial.print( (int)(elapsedTime / 1000L) ); // divide by 1000 to convert to seconds - then cast to an int to print Serial.print("."); // print decimal point fractional = (int)(elapsedTime % 1000L); // use modulo operator to get fractional part of time Serial.println(fractional); // print fractional part of time
The problem lies in the fractional part. Since an intiger cannot begin with a zero (this is then ignored) times (millis()) with zero (0) at the first digit of the fractional part (tenths of a second) are wrongly displayed since the 0 is ignored and the other 2 decimals are moved one digit, turning hundreds of a second into tenths and thousands of a second into hundreds.
So 14565 ms is correctly displayed as 14,565 seconds, but 14065 ms is displayed as 14,65 seconds i.s.o. 14,065 seconds which is halve a second off :o
(and the difference can be max 0,891s)
I only found the problem when displaying the millis() on a 7 segment display and when a zero was displayed at the right of the decimal point, the serial output and the displayed value were not corresponding. So people only using this example through serial port might not find the problem at all (or they read the code better then I do before they use it)
I solved the problem with the following code by adding the zero when the fractional part is smaller than 100, but here are probably more and/or neather solutions to solve it
Code:
Serial.print( (int)(elapsedTime / 1000L) ); // divide by 1000 to convert to seconds - then cast to an int to print Serial.print("."); // print decimal point fractional = (int)(elapsedTime % 1000L); // use modulo operator to get fractional part of time if (fractional < 100) // if fractional < 100 the 0 is ignored giving a wrong time, so add the zero { Serial.print("0"); // add zero Serial.println(fractional); // print fractional part of time } else { Serial.println(fractional); // print fractional part of time }
I know it is only with the serial print function, so when importing the time into another program one will probably use a different method. But i found it worth mentioning since I use the serial print a lot for debugging purposes!
So please take note when using the stopwatch example from the arduino site.
Since I'm getting the problem sometimes (so not all the time) that the software cannot upload to the arduino board giving the:
Quote
stk500_recv(): programmer is not responding avrdude:
nothing works then such as reset, unplug and wait a minute, restart the computer etc... but when I unplug the wire to the ground pin... EUREKA... it's working again. I got a few LEd displays and a few buttons connected to ground (even split it up over the other ground pins, but I guess they are all connected internally...
so the big question is:
Is it possible to connect to much connections to the ground pin(s)??
ok, thanks very much for your reply. I could not find the correct word for it (i'm from the netherlands) so googling is a hard task then... This will help a lot.
So just got my Arduino and love the simplicity of it. I do encounter one problem though.
I have a simple code that flashes the led in pin 13 when a digitalRead in another channel (i used 9) is HIGH. So, when I wire up the 5V to channel 9, the led should blink. Not so hard is it.
But when I do not wire up the 5V to channel 9, and move my hand somewhere near the arduino... the led flashes. So there is some sort of static electricity around the board. See the not so clear youtube movie:
Project is kinda hidden in the basement at the moment. Had some problems with powering (but probably due to my lack of knowledge) and the IR-controler had some difficulties in bright sunlight (=huge IR source). Since the IR-beam was just a kit, it's kinda hard to put a pot meter in it for sensitivity adjustment.
So that's the status at the moment. For my camera I made remote with laser beam and I think it would be easy to fit it into this project.
The rest is just simple push buttons and flip switches. Wiring up the 7 segement displays is also very simple and there is a good guide on the arduino site (and I hooked up 5 in serie i.s.o. the 2 in the example).
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);
// 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(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:
1. check is reset button is pressed, IF SO, stop time or set display to zero 2. check if last lap button is pressed, IF SO, show last lap on display, keep time running 3. check if delay button is closed, IF SO, don't do anything when beam is broken 3. 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) 4. when time is running, blink LED and keep updating display (only whole seconds) 5. 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