Some comments on your code:
Auto Format (under the tools menu or CTRL-T) makes the code much easier to read
Remove extra blank lines - makes the code easier to read
Move the call to the arming routine to the setup. It only needs to run once.
I do not like that the motor is running with low throttle (1000). I wonder if you should write 1000 to the ESC just before you attach.