Pause writing to SD card and resume in the same file


I was wondering if it is possible to pause writing to Sd card with the help of a push button and resume writing to the sd card (by pressing the push button again) in the same file without creating a new file on the Sd card using SD.h library?

Thank you!

You can by simply not closing the file. But be careful: the library caches (buffers) data in blocks of 512 bytes before actually writting them into the card; any data that still remains only in RAM will be lost if the Arduino resets or powers off (during the pause in this case). If the recording isn't time-critical, you can avoid this by calling flush(); you usually close the file when you're really done with it.

Can we do so by using the same push button to pause and resume? Like a single push button to do both?

The meaning you give to the button push depends on your application, so there is no reason that you cannot use the same switch for both. You just need to know if the file is paused or not an then restart or pause (ie, the opposite action).

The state change detection example shows how to determine that a switch HAS BECOME pressed (or released) and to take different actions based on the number of times that has happened. So, yes, it is possible. Trivial, even.