Simple sleep code for Arduino MEGA

Hi!

I have a little program for my MEGA with a motor, buttons and so.
It runs on batteries, and I would love to put it to sleep for saving power.

Is there any simple code out there wich I can just put into my code without it messing with the program?

I'd like it to for example go to sleep after 3 minutes of inactivity, but when a button is pressed it starts from where it was last.

The first 2 External Interrupts are busy for the rotarcy encoder, but the others Ext Int are free, if these must be used? :o

Best regards
U

Is there any simple code out there wich I can just put into my code without it messing with the program?

That depends entirely on what you mean by "messing with". Of course, you are going to make changes to your program.

If you were smart, at the end of loop(), you'd call a function to sleep, if appropriate. That function would not return until the wake-back-up event happened, at which point loop() would iterate again.