Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ The potientiometer can be used to rotate the players field of view, i.e what the
4. Install the repository to the ChipKit.

```bash
make
make install
mini-project/src$ make
mini-project/src$ make install
```

5. Follow the instructions on the screen and enjoy.
Expand All @@ -50,6 +50,8 @@ For further installation instructions regarding the mcb32 toolchain, we recommen

## Contributing

This project was made by Bernard Rumar (bernardr) & Fredrik Magnevill (magnev).

This is a school project which means no contributions are allowed.

## License
Expand Down
2 changes: 1 addition & 1 deletion src/calculateScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void castRay(float* playerDirection, int* playerPosX, int* playerPosY, int map[]
if (ca > 2*PI) {
ca -= 2*PI;
}
disT = disT * cos(ca); // fix fishbowl effect
//disT = disT * cos(ca); // fix fishbowl effect
// Draw one line of the wall
drawLine(display, r, disT, 1);

Expand Down
Binary file modified src/calculateScreen.c.o
Binary file not shown.
16 changes: 11 additions & 5 deletions src/control.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#include <pic32mx.h>


// Initialize the Interrupt Service Routine (ISR)
void user_isr(int* walking, float* playerDirection);
// havent used
// void set_interrupts(void);
// void open_ports(void);

// fucks up screen
// void initTimer(void);
// Interrupts
void set_interrupts(void);
void open_ports(void);

// Timer
void initTimer(void);

// Analog-to-digital converter (ADC), for potentiometer
void initADC(void);
int readADC(void);

// Buttons
int getbtns(void);
79 changes: 38 additions & 41 deletions src/gyroControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,51 @@
* @param playerDirection: pointer to a float that indicates the direction the player is facing
*/
void user_isr(int* walking, float* playerDirection) {
if (getbtns() & BTN4) {
*walking = *walking ? 0 : 1;
// wait for timer interrupt - aka ticks every 0.1 seconds
if (!(IFS(0) & 0x100)) {

if (getbtns() & BTN4) {
*walking = *walking ? 0 : 1;
}

// convert to a float between 0 and 1
float potentiometerFloat = (float)readADC() / 1023;
// convert to a float between 0 and 2pi
*playerDirection = potentiometerFloat * 2 * PI;
}

// convert to a float between 0 and 1
float potentiometerFloat = (float)readADC() / 1023;
// convert to a float between 0 and 2pi
*playerDirection = potentiometerFloat * 2 * PI;
}

// void set_interrupts(void) {
// // enable interrupts globally
// asm volatile("ei");
// }

// void open_ports(void) {
// // set PORTD as input
// TRISDSET = 0x7F0;
// // set PORTE as output
// TRISECLR = 0xFF;
// }

// void initTimer(void) {
// // initialize timer 1
// T1CON = 0x70; // set prescaler to 256
// PR1 = 3125; // set period to 0.1 seconds
// TMR1 = 0; // reset timer
// T1CONSET = 0x8000; // start timer

// // set timer interrupt
// IPCSET(2) = 0x1C; // set priority to 7
// IFSCLR(0) = 0x100; // clear interrupt flag
// IECSET(0) = 0x100; // enable interrupt

// reset interrupt flag
IFSCLR(0) = 0x100;

// // the timer ticks every 0.1 seconds
// reset timer
TMR1 = 0;

// // wait until timer interrupt flag is set
// while (!(IFS(0) & 0x100));
// // reset timer interrupt flag
// IFSCLR(0) = 0x100;

// // reset timer
// TMR1 = 0;
}

// }
void set_interrupts(void) {
// enable interrupts globally
asm volatile("ei");
}

void open_ports(void) {
// set PORTD as input
TRISDSET = 0x7F0;
// set PORTE as output
TRISECLR = 0xFF;
}

void initTimer(void) {
// initialize timer 1
T1CON = 0x70; // set prescaler to 256
PR1 = 3125; // set period to 0.1 seconds
TMR1 = 0; // reset timer
T1CONSET = 0x8000; // start timer

// set timer interrupt
IPCSET(2) = 0x1C; // set priority to 7
IFSCLR(0) = 0x100; // clear interrupt flag
IECSET(0) = 0x100; // enable interrupt
}

void initADC() {
/* PORTB.2 is analog pin with potentiometer*/
Expand Down
Binary file modified src/gyroControl.c.o
Binary file not shown.
9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ void init() {

// initialize the ADC module (to read potentiometer)
initADC();

set_interrupts();

open_ports();

initTimer();
}

void main() {
Expand Down Expand Up @@ -90,8 +96,11 @@ void main() {
while (1) {
// if button 4 is pressed - start game
if (getbtns() & 0x4) {
// can remove for actual game
display_string(textbuffer, 1, "BTN4 pressed");
display_update(textbuffer);

// keep for actual game
quicksleep(500000);
clear_display(textbuffer);
display_update(textbuffer);
Expand Down
Binary file modified src/main.c.o
Binary file not shown.
17 changes: 9 additions & 8 deletions src/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ float sqrt(float n) {
return x;
}

float floor(float x){
return (int) x;
}

float ceil(float x){
return (int) x + 1;
}

float pow(float base, float exponent){
float result = 1;
Expand All @@ -79,4 +72,12 @@ float pow(float base, float exponent){
result *= base;
}
return result;
}
}

float floor(float x){
return (int) x;
}

float ceil(float x){
return (int) x + 1;
}
Binary file modified src/math.c.o
Binary file not shown.
9 changes: 8 additions & 1 deletion src/math.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#define PI 3.1415926535
#define DR 0.01745329251

// Trigonometrical fucntions
float sin(float rad);
float cos(float rad);
float tan(float rad);

// conversion functions
float deg_to_rad(float deg);
float rad_to_deg(float rad);

// exponential functions
float sqrt(float n);
float pow(float base, float exponent);

// rounding functions
float floor(float x);
float ceil(float x);
float pow(float base, float exponent);
Binary file modified src/outfile.elf
Binary file not shown.
Loading