Project #1:

Hardware:
In this project, you will be using the Explorer 16 development board. Specifically, you will be using the 8 LEDs on the board to generate a Knight Rider Pattern on those LEDs. Please, check Explorer16.pdf for pin connections.
Part A:
Write an application (in C) which implement the sequence as below:
1. Make all the LEDs OFF.
2. Make LED D3 (Right most) to be ON .
3. After a while (a delay of your choice), make next (to the Left) LED to be ON.
4. After a while, make the next LED to be ON. Repeat this process until all the 8 LEDs (from Right most to LEFT most) becomes ON.
5. Repeat the above processes (1-4), this time, starting from LEFT most LED and walk to the RIGHT most.
6. Repeat the above sequence (1-5) infinitely.
Note: Develop the application as described above and demo to your prof., for evaluation.

Part B:
Utilize SW3 of the explorer 16 board to change the direction of the Knight Rider Pattern designed in Part A. Any time, if SW3 is pushed down and hold, the above pattern starts from LEFT to RIGHT and when SW3 is released, the pattern walks from RIGHT to LEFT (as in Part A).
Note: Implement Part B and demo to your prof., for evaluation.

1 answer

In order to complete Part A of the project, here is an example code in C that describes how to implement the Knight Rider Pattern on the Explorer 16 development board:

```c
#include <p24Fxxxx.h>

#define DELAY_TIME 50000 // You can adjust this delay value according to your preference

// Function to initialize the Explorer 16 development board
void initExplorer16() {
AD1PCFG = 0xffff;
TRISA = 0xFF00;
}

// Function to turn off all the LEDs
void turnOffLEDs() {
LATA = 0x00;
}

// Function to turn on a specific LED
void turnOnLED(int pin) {
LATA = 0x01 << pin;
}

int main(void) {
initExplorer16();
int direction = 1; // 1 for left to right, -1 for right to left
int currentLED = 0;

while (1) {
turnOffLEDs();

if (currentLED >= 0 && currentLED < 8) {
turnOnLED(currentLED);
currentLED += direction;
} else {
direction *= -1; // Reverse the direction
currentLED += direction;
}

// Delay to control the speed of the pattern
int count = DELAY_TIME;
while (count > 0) {
count--;
}
}

return 0;
}
```

To complete Part B of the project, you need to modify the code to include the functionality of SW3. Here is an updated code that includes the necessary changes:

```c
#include <p24Fxxxx.h>

#define DELAY_TIME 50000

void initExplorer16() {
AD1PCFG = 0xffff;
TRISA = 0x00FF; // Set the lower 8 pins of PORTA as input
TRISBbits.TRISB5 = 1; // Set RB5 as input
}

void turnOffLEDs() {
LATA = 0x00;
}

void turnOnLED(int pin) {
LATA = 0x01 << pin;
}

int main(void) {
initExplorer16();
int direction = 1;
int currentLED = 0;

while (1) {
turnOffLEDs();

if (direction == 1) {
if (currentLED >= 0 && currentLED < 8) {
turnOnLED(currentLED);
currentLED += direction;
} else {
direction *= -1;
currentLED += direction;
}
} else {
if (currentLED >= 0 && currentLED < 8) {
turnOnLED(7 - currentLED);
currentLED += direction;
} else {
direction *= -1;
currentLED += direction;
}
}

// Check if SW3 is pressed
if (PORTBbits.RB5 == 0) {
direction = 1; // Start from left to right
} else {
direction = -1; // Start from right to left
}

int count = DELAY_TIME;
while (count > 0) {
count--;
}
}

return 0;
}
```

Please note that this code assumes the Explorer 16 development board with the LEDs connected to PORTA and SW3 connected to RB5. Make sure to consult the Explorer16.pdf document for the pin connections and adjust the code accordingly.