analogWrite not functioning in if statement

Er, you can restructure to not use delays. It's not that hard. Depends what you want.