 **    each time through the main program loop.
 */
 
-void
-AppTask()
-  {
-  unsigned int	dwBtn;
-
-  /* Check the state of button 1 on the PmodJSTK and set LED 1
-  ** accordingly
-  */
-  dwBtn = fbBtnPmod & 0x01;
-  if (dwBtn == 0) {
-    digitalWrite(PIN_LED1, LOW);
-  }
-  else {
-    digitalWrite(PIN_LED1, HIGH);
-  }
-
-  /* Check the state of button 2 and set LED 2 accordingly
-  */
-  dwBtn = fbBtnPmod & 0x02;
-  if (dwBtn == 0) {
-    digitalWrite(PIN_LED2, LOW);
-  }
-  else {
-    digitalWrite(PIN_LED2, HIGH);
-  }
-
-  /* Check if it is time to blink LED3 & LED4 and update
-  ** the joystick.
-  */
-  cntBtnBlink -= 1;
-  if (cntBtnBlink == 0) {
-    
-  #if defined(PIN_LED3)
-    digitalWrite(PIN_LED3, fLed3);
-    fLed3 = (fLed3 == HIGH) ? LOW : HIGH;
-  #endif
-  
-  #if defined(PIN_LED4)
-    digitalWrite(PIN_LED4, fLed4);
-    fLed4 = (fLed4 == HIGH) ? LOW : HIGH;
-  #endif
-
-    /* Toggle the setting for the LEDs on the joystick.
-    */
-    fbLedPmod ^= 0x03;
-    
-    /* Update the joystick.
-    */
-    ReadJoystick(fbLedPmod, &fbBtnPmod, &xcoPmod, &ycoPmod);
-
-    cntBtnBlink = cntBlinkInit;
-  }
+void AppTask() {
+    unsigned int	dwBtn;
+    /* Check the state of button 1 on the PmodJSTK and set LED 1
+    ** accordingly
+    */
+    dwBtn = fbBtnPmod & 0x01;
+
+    if (dwBtn == 0) {
+        digitalWrite(PIN_LED1, LOW);
+    } else {
+        digitalWrite(PIN_LED1, HIGH);
+    }
+
+    /* Check the state of button 2 and set LED 2 accordingly
+    */
+    dwBtn = fbBtnPmod & 0x02;
+
+    if (dwBtn == 0) {
+        digitalWrite(PIN_LED2, LOW);
+    } else {
+        digitalWrite(PIN_LED2, HIGH);
+    }
+
+    /* Check if it is time to blink LED3 & LED4 and update
+    ** the joystick.
+    */
+    cntBtnBlink -= 1;
+
+    if (cntBtnBlink == 0) {
+#if defined(PIN_LED3)
+        digitalWrite(PIN_LED3, fLed3);
+        fLed3 = (fLed3 == HIGH) ? LOW : HIGH;
+#endif
+#if defined(PIN_LED4)
+        digitalWrite(PIN_LED4, fLed4);
+        fLed4 = (fLed4 == HIGH) ? LOW : HIGH;
+#endif
+        /* Toggle the setting for the LEDs on the joystick.
+        */
+        fbLedPmod ^= 0x03;
+        /* Update the joystick.
+        */
+        ReadJoystick(fbLedPmod, &fbBtnPmod, &xcoPmod, &ycoPmod);
+        cntBtnBlink = cntBlinkInit;
+    }
 }
 
 /* ------------------------------------------------------------ */

**    Delay loop for ~10uS
*/

void
Delay10us()
  {
  volatile int		cnt;

  for (cnt = 0; cnt < 100; cnt++) {
  }

}

/* ------------------------------------------------------------ */

/************************************************************************/



**  Description:
**    Read the current position of the joystick and buttons.
*/
void ReadJoystick(uint8_t fbLed, uint8_t * pfbBtn, int * pxco, int * pyco) {
    uint8_t    rgbSnd[5];
    uint8_t    rgbRcv[5];
    int	     ib;

    /* Initialize the transmit buffer.
    */
    for (ib = 0; ib < 5; ib++) {
        rgbSnd[ib] = 0x50 + ib;
    }

    rgbSnd[0] = fbLedPmod + 0x80;  //first byte sent sets the LEDs
    /* Bring SS low to begin the transaction.
    */
    spi.setSelect(LOW);
    /* Wait 10us for Pmod to become ready
    */
    Delay10us();
    /* Send the data to the Pmod and get the response.
    */
    spi.transfer(5, rgbSnd, rgbRcv);
    /* Bring SS high to end the transaction.
    */
    spi.setSelect(HIGH);
    /* Set up the return values.
    */
    *pfbBtn = rgbRcv[4] >> 1;
    *pxco = (uint16_t)((rgbRcv[1] << 8) + rgbRcv[0]);
    *pyco = (uint16_t)((rgbRcv[3] << 8) + rgbRcv[2]);
}

/* ------------------------------------------------------------ */
