Trouble combining sleep with if/else toggle

Hi all,
this is my first time playing with the arduino. Haven’t really mucked about with code/electronics since uni (maybe 10 years ago…) so apologies if my code errors are obvious.

I’m trying to toggle between two servo positions; the opposite one each time the arduino wakes.

I’ve tried playing with the delay time and moving the boolean toggle and sleep function call outside the if/else scope with no success. I’ve also gone for extreme (0/180) servo val’s to check that I wasn’t having servo position problems.

Every combo seems to wake up, give a little wiggle (~30 deg) on the servos and then sleep.

I’ve attached the code and would love some input.
:slight_smile:

suspension_lockout.ino (1.59 KB)

How long does it take one of your servos to rotate 115 to 135 degrees? You are only allowing 150 milliseconds, before going back to sleep. Are you (mistakenly) expecting the servos to keep moving while the Arduino is beddy-bye?

I’ve tried upping it to 5 seconds and still get the same result, just slower…

Welcome to the Forum. Please read this post: How to use this forum - please read. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.