Looking again at your code you are switching on for 18 ms and off for 2 ms, this is wrong. You only need one loop. If you want to make it go back and forth you need to try this. Set out for 1 ms on delay 18 ms .....do 50 times, set out for 1.5 ms on delay 18 ms....do 50 times, set out for 2 ms...