That looks like it would work. But i would add some code to keep it from trying to go beyond the angle limits of your servo. Not sure how necessary it would be, but I like to add error trapping in all my code. Of course I'm used to programming PCs which the added memory usage is insignificant compared to potential problems.