Something like this?

Code:
main:

     ' somewhere in main

    if ButtonIsPressed then gosub ButtonProcess

    goto main


ButtonProcess:
     gosub SendHeader                    ' send the 010001010 pattern with this subroutine
     while ButtonIsPressed               ' as long as the button remains pressed,
          gosub SendBody                 ' send the body pattern
          Pause xxx                          ' followed by the pause
     wend                                      ' loop @ while statement

     '  when button is released, you may want to send something too!!
     gosub SendTrailer                    ' similar to the header but sent at end of button press.  Makes it a bit exciting !!
return
Regards