However you'd need to somehow set this, and there is no way to do this without some sort of external hardware, i.e either a realtime clock module, or other clever solutions like getting the time via a Wifi connection etc.
Secondly, in your loop you need to wait for the "switchPin" to change state (ie as a function of the debounce code)
i.e if the switch is active high, then without debounce you would need to do something like this
void loop(){
while(!digitalRead(switchPin)); // Poll waiting for the switch to go HIGH (NOTE THIS NEEDS TO BE DEBOUNCED !!!!)
// delay(70); // this is pointless if you use debounce
perTipped += 0.50;
nt += 1;
myFile = SD.open("robin.txt", FILE_WRITE);
myFile.print(perTipped);
myFile.print(" ");
myFile.println(nt);
myFile.close();
Serial.write(0x02); //STX
Serial.print(">"); // Send position info
Serial.print(a);
Serial.write(0x03); //ETX
Serial.write(0x02); //STX
Serial.print("3");
Serial.print(perTipped); //
Serial.write(0x03); //ETX
//---------------------------------------
Serial.write(0x02); //STX
Serial.print(">"); // Send position info
Serial.print(a);
Serial.write(0x03); //ETX
Serial.write(0x02); //STX
Serial.print("4");
Serial.print(nt); //
Serial.write(0x03); //ETX
};
However you'd need to somehow set this, and there is no way to do this without some sort of external hardware, i.e either a realtime clock module, or other clever solutions like getting the time via a Wifi connection etc.
I agree with Roger, I think external hardware for keeping time is your best bet. Check out Adafruit's DS1307 module;
You can stack it right on your Arduino, and it will last for ~5 years. It will also keep time while the Ardunio is off. Also, her tutorials accompanying this chip will also answer many questions about how to utilize a Real Time Clock (RTC). It helped me out with my plant watering system;
If you can't wait for the RTC module, download the library it uses(example "softRTC"). This example "fakes" an RTC module using Millis(). It's incredibly inaccurate over the long run, but it will get you started with RTC code;
I think it would help to describe your project in more detail.
In particular ...
How often does the bucket tip? (shortest and longest intervals)
What sort of signal is produced when the bucket tips?
How long is the "bucket tipped" signal available to be detected?
I suspect that, in an Arduino context, the bucket tips very infrequently even at its fastest.
If that is true all you need is code to check the state of the bucketTipped pin every iteration of loop and use millis() or the RTC to measure the time.
When the code detects bucketTipped it can calculate the elapsed time since the previous tip and write the number to the SD card. Even if that takes a few millisecs there is no (?) likelihood of another bucketTip in such a short time.