Can Arduino continue executing a code at some point after it's turned off and back on again? So that it doesn't reset and start from beginning.
For example:
Arduino ON - Servo horn goes from 90° to 0°
Arduino OFF - Servo horn stays at 0°
Arduino ON - Servo horn goes from 0° to 90°
Arduino OFF - Servo horn stays at 90°
And the cycle repeats. Switching on and off will be done by a relay, triggered by a sensor.
There are no delays in the code.
So basically it's a loop that doesn't reset when switching the Arduino on and off.
You might be able to save a variable that records the current state of the program and regularly writes the value of that variable to EEPROM. Then, in setup(), you would read the EEPROM value at startup, and use a switch/case block to determine which function(s) get called. Once the startup code finishes, control goes to loop() which records the new state in EEPROM and the program continues. One fly in the ointment, however, is that EEPROM has a finite number of write cycles before it gets flaky. Therefore, you probably can't update the state stored in EEPROM on every pass through the loop. You'd need to compromise on that.
Does your servo always turn to 0° to 90° and viceversa? In case you can setup a couple of limit switch on both position, read it with your arduino at start so you'll know the position where the servo is left and acting according.