So I have my code working where I'm happy with the exception that I need a way to stop the program after an event.
In this case I am recording to SD when analog value is over 500 and when under 500 I retrieve the data via Bluetooth. The issue I have is after the data on the SD has been sent the program starts writing again through the loop. How do I make it stop? I tried a delay of 10 minutes just so it gives time to turn it off. But I would much prefer a situation where
if the value is below threshold
write sd through bluetooth
AND STOP HERE..
else if the value is above threshold
run loop continuously until turned off.
I've looked all over the place for how I could do this. I tried while statements and if statements, I just cant find a way for it to stop other than a really long delay....which isn't really stopped
Well adding the following statement where ever you wish in your sketch will create an endless loop which is as effective as a true stop. The AVR chip has no halt instruction so a endless loop will serve just as well. Interrupts will still be processed which may or may not be an issue in your sketch.
while (1) { } // stay looping in this statement until powered off or reset pushed.
while (logFile.available()) {
Serial2.write(logFile.read()); }
// close the file:
logFile.close();
if(SD.exists("LOG.csv"));
SD.remove ("LOG.csv");
}}
then I have my loop stuff here.. I tried putting in the if statements in the loop and couldn't get it to works as well as it does here..
the rest of the loop is long so I didn't post it as it has all the GPS stuff...
// if the file didn't open, print an error:
Serial.println("Starting Log...");