Add an interrupt the Left to Right direction sequence when RD6 is pressed on Explorer 16

unsigned int count1 = 500;
unsigned int count2 = 500;
unsigned int timerValue = 0;

int main(void){
TRISA = 0x00; // Set PORTA as output
TRISDbits.TRISD6 = 1; // Set SW3 input

int i;
int j;

while(1) {
// Toggle RUN LED (D10) every 3.5 seconds using Timer1
LATDbits.LATD0 = !LATDbits.LATD0;
delayFunc();

// Knight Rider pattern from Left to Right direction
for(i = 0; i <= 6; i++) {
LATA = (1 << i);
delayFunc();
}

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 state
if (PORTDbits.RD6 == 0) {
for(j = 6; j >= 0; j--) {
LATA = (1 << j);
delayFunc();
}
} else {
for( j = 0; j <= 7; j++) {
LATA = (1 << j);
delayFunc();
}
}
}

return -1;

}

void delayFunc(void)
{
int j,k;
int a;

for(j = 0; j < count1; j++)
{
for(k=0; k < count2; k++)
{
a = 0;
}
}
}

To add an interrupt to the Left to Right direction sequence when RD6 is pressed on the Explorer 16 board, follow these steps:

1. Declare an interrupt function at the beginning of the code:
```c
void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
{
// Set the interrupt flag back to 0
IFS0bits.INT0IF = 0;

// Knight Rider pattern from Left to Right direction
for(int i = 0; i <= 6; i++) {
LATA = (1 << i);
delayFunc();
}
}
```

2. Enable the external interrupt and set its priority in the `main` function:
```c
int main(void)
{
// ...

// Enable external interrupt on RD6/INT0 and set its priority
INTCON2bits.INT0EP = 1; // Detect falling edge
IPC0bits.INT0IP = 4; // Set priority to 4
IEC0bits.INT0IE = 1; // Enable the interrupt

while(1) {
// ...
}

// ...
}
```

3. In the `while(1)` loop, add a check for the interrupt flag to toggle the Knight Rider pattern direction based on the state of RD6:
```c
while(1) {
// ...

// Knight Rider pattern: Left to Right or Right to Left depending on SW3 (RD6) state
if (PORTDbits.RD6 == 0) {
for(j = 6; j >= 0; j--) {
LATA = (1 << j);
delayFunc();
}
} else {
for( j = 0; j <= 7; j++) {
LATA = (1 << j);
delayFunc();
}
}
}
```

4. Implement a delay function to provide a delay between LED changes in the Knight Rider pattern. You can use the existing `delayFunc` function in the code.