Go Down

Topic: Do we have a teardown() function on the same lines of setup() function (Read 150 times) previous topic - next topic

vikalpsetya

Greetings,
I am making a speedometer cum odometer using Arduino UNO, a 128*64 LCD and a reed switch for my motorbike.
My query is that do we have any kind of teardown() function in Arduino that I could override in my sketch to write some clean-up stuff like persisting odo reading to EEPROM?
Any other callback function that gets invoked immediately before Arduino is disconnected from power would also serve my purpose.

ardy_guy

function that gets invoked immediately before Arduino is disconnected from power
How would it know until it was too late?

[irishAccent]Have you tried turning it off and on again?[/irishAccent]

septillion

Short answer, nope.

An option would be to give the Arduino a (super) cap as backup and detect when the normal power is disconnected and run your function.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

BulldogLowell

you could make a circular buffer in EEPROM and just write every mile.

I didn't do the math, but with a 24bit number you could put at least a million writes to EEPROM if you are leveling

UKHeliBob

Quote
Any other callback function that gets invoked immediately before Arduino is disconnected from power would also serve my purpose.
That would be a neat trick.  How would the program know that you were about to turn off the power ?

You could write your own "teardown()" function and invoke it with say a pushbutton.  The function could control a relay or transistor that supplies power to the Arduino so could turn it off.  You would, however, then need a mechanism to turn it on again.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulMurrayCbr

What everyone else said. When - under what set of conditions - would such a teardown() function be invoked? Silicon ain't psychic.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

PaulS

The art of getting good answers lies in asking good questions.

Go Up