Smart Blind

I'm an another beginner who started a project that looked simple at the beginning. I have some programming problem with the calibration part of the lenght of the window. What I want is that: When you plug in the system it is waiting to push the button and when you push it it's start to going up and when it reaches the highest position you press it again and it's going down and when it is in the lowest position you press it again, it stoppes and it is store the number of the rotations.
I would be very happy If someone have something similar code that can help me to make my own!
Thank you!

what I use for that:
-arduino nano
-modded 28byj-48
-one button
-power supply, etc.