'{$STAMP BS2}
'{$PBASIC 2.0}
'Program 1
Cnt VAR Byte                 'Variable for counting
PB1 VAR IN1                  'Variable for PB1 input
LED1  CON 4                  'Variable for LED1 output

INPUT 1                      'Set PB1 as input
OUTPUT 4                     'Set LED1 as output

LOW LED1                     'Turn off LED

Start:
  IF PB1 = 0 THEN Start      'Not Pressed? Go back to loop
  GOSUB Blink_LED1           'If it was pressed then perform subroutine
GOTO Start                   'After return, go back to start

Blink_LED1:                  'Subroutine to blink LED 5 repetitions
  FOR Cnt = 1 TO 5           'Setup loop for 5 counts
    HIGH LED1                'Turn ON LED
    PAUSE 1000               'Wait 1 second
    LOW LED1                 'Trun off LED
    PAUSE 1000               'Wait 1 second
  NEXT                       'Repeat loop until done

RETURN                       'return back to after gosub call