

/// LED1
#define CONFIG_LED1() CONFIG_RB10_AS_DIG_OUTPUT()
#define LED1  _LATB10     //led1 state

/// Switch1 configuration
inline void CONFIG_SW1()  {
  CONFIG_RB11_AS_DIG_INPUT();     //use RB11 for switch input
  ENABLE_RB11_PULLUP();           //enable the pullup
}
#define SW1              _RB11       //switch state
#define SW1_PRESSED()   (SW1==0)  //switch test
#define SW1_RELEASED()  (SW1==1)  //switch test

int main (void) {
  configBasic(HELLO_MSG);      // Set up heartbeat, UART, print hello message and diags
  /** GPIO config ***************************/
  CONFIG_SW1();        //configure switch
  CONFIG_LED1();       //configure LED
  DELAY_US(1);         //give pullups a little time
  LED1 = 0;            //LED off initially
  while (1) {
    // wait for press
    while (SW1_RELEASED()) doHeartbeat(); //loop (1)
    DELAY_MS(15); //debounce
    // wait for release
    while (SW1_PRESSED()) doHeartbeat(); //loop (2)
    DELAY_MS(15); // debounce
    LED1 = !LED1;  //toggle the LED
  }
}
