testing documentation

Dependencies:   mbed ll16j23s_test_docs

Committer:
JoeShotton
Date:
Sat May 23 15:31:30 2020 +0000
Revision:
4:ea3fa51c4386
Parent:
3:fcd6d70e9694
Child:
5:06fa7674622a
Food and snake collisions implemented, still buggy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 0:b7f1f47bb26a 1 /*
eencae 0:b7f1f47bb26a 2 ELEC2645 Embedded Systems Project
eencae 0:b7f1f47bb26a 3 School of Electronic & Electrical Engineering
eencae 0:b7f1f47bb26a 4 University of Leeds
eencae 0:b7f1f47bb26a 5 2019/20
eencae 0:b7f1f47bb26a 6
JoeShotton 2:86b67b492cbc 7 Name: Joe Shotton
JoeShotton 2:86b67b492cbc 8 Username: ll16j23s
JoeShotton 2:86b67b492cbc 9 Student ID Number: 201127267
JoeShotton 2:86b67b492cbc 10 Date: 4/4/20
eencae 0:b7f1f47bb26a 11 */
eencae 0:b7f1f47bb26a 12
eencae 0:b7f1f47bb26a 13 // includes
eencae 0:b7f1f47bb26a 14 #include "mbed.h"
eencae 0:b7f1f47bb26a 15 #include "Gamepad.h"
eencae 0:b7f1f47bb26a 16 #include "N5110.h"
JoeShotton 3:fcd6d70e9694 17 #include "FXOS8700CQ.h"
JoeShotton 3:fcd6d70e9694 18 #include "SnakeEngine.h"
JoeShotton 3:fcd6d70e9694 19 #include <vector>
JoeShotton 3:fcd6d70e9694 20 #include <cstdlib>
eencae 0:b7f1f47bb26a 21
JoeShotton 1:985dfa6cee28 22 #define X_MAX 84
JoeShotton 1:985dfa6cee28 23 #define Y_MAX 48
eencae 0:b7f1f47bb26a 24
eencae 0:b7f1f47bb26a 25 // objects
eencae 0:b7f1f47bb26a 26 Gamepad pad;
eencae 0:b7f1f47bb26a 27 N5110 lcd;
JoeShotton 3:fcd6d70e9694 28 SnakeEngine snake;
JoeShotton 3:fcd6d70e9694 29 FXOS8700CQ device(I2C_SDA,I2C_SCL);
eencae 0:b7f1f47bb26a 30
JoeShotton 1:985dfa6cee28 31 int main() {
JoeShotton 1:985dfa6cee28 32
JoeShotton 1:985dfa6cee28 33 lcd.init();
JoeShotton 1:985dfa6cee28 34 pad.init();
JoeShotton 1:985dfa6cee28 35
JoeShotton 1:985dfa6cee28 36 float speed = 0.5;
JoeShotton 3:fcd6d70e9694 37
JoeShotton 1:985dfa6cee28 38 int fps = 25;
JoeShotton 1:985dfa6cee28 39 int frame_t = 1000/fps;
JoeShotton 2:86b67b492cbc 40 bool death = false;
JoeShotton 3:fcd6d70e9694 41
JoeShotton 3:fcd6d70e9694 42 //int length = 10; //intial snake size
JoeShotton 3:fcd6d70e9694 43 //int size_inc = 5; //how much longer the snake gets due to food
JoeShotton 1:985dfa6cee28 44
JoeShotton 1:985dfa6cee28 45
JoeShotton 3:fcd6d70e9694 46 //int d = 0; //direction starts in centre
JoeShotton 3:fcd6d70e9694 47 //int state = 0; //first state is centre of joystick
JoeShotton 3:fcd6d70e9694 48
JoeShotton 3:fcd6d70e9694 49 /*
JoeShotton 1:985dfa6cee28 50 Dir fsm[5] = {
JoeShotton 1:985dfa6cee28 51 {0, 0, 0, {0,1,2,3,4}}, // Centred
JoeShotton 1:985dfa6cee28 52 {1, 0, -1, {1,1,2,1,4}}, // North, will not go to centre or south
JoeShotton 1:985dfa6cee28 53 {2, 1, 0, {2,1,2,3,2}}, // East, will not go to centre or west
JoeShotton 1:985dfa6cee28 54 {3, 0, 1, {3,3,2,3,4}}, // South, will not go to centre or north
JoeShotton 1:985dfa6cee28 55 {4, -1, 0, {4,1,4,3,4}} // West, will not go to centre or east
JoeShotton 1:985dfa6cee28 56 };
JoeShotton 3:fcd6d70e9694 57 */
JoeShotton 4:ea3fa51c4386 58 while(death == false){
JoeShotton 1:985dfa6cee28 59
JoeShotton 4:ea3fa51c4386 60 //printf("Running!");
JoeShotton 3:fcd6d70e9694 61
JoeShotton 1:985dfa6cee28 62 speed = pad.read_pot2();
JoeShotton 1:985dfa6cee28 63
JoeShotton 4:ea3fa51c4386 64 lcd.clear();
JoeShotton 4:ea3fa51c4386 65 snake.move_body(pad, lcd, death);
JoeShotton 4:ea3fa51c4386 66 lcd.setContrast(0.4);
JoeShotton 4:ea3fa51c4386 67 lcd.refresh();
JoeShotton 4:ea3fa51c4386 68 wait_ms(500/(5+snake.score));
JoeShotton 4:ea3fa51c4386 69 }
JoeShotton 4:ea3fa51c4386 70 }
JoeShotton 4:ea3fa51c4386 71
JoeShotton 3:fcd6d70e9694 72 /* if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) {
JoeShotton 2:86b67b492cbc 73 // checks infront of head to see if pixel is set
JoeShotton 2:86b67b492cbc 74 // due to the size of the head, there is an offset for the check for North and Eastward directions
JoeShotton 2:86b67b492cbc 75 death = true;
JoeShotton 2:86b67b492cbc 76 pad.led(1,0.9);
JoeShotton 2:86b67b492cbc 77 } else {
JoeShotton 2:86b67b492cbc 78 death = false;
JoeShotton 2:86b67b492cbc 79 pad.led(1,0.0);
JoeShotton 2:86b67b492cbc 80 }
JoeShotton 3:fcd6d70e9694 81 */
JoeShotton 3:fcd6d70e9694 82
JoeShotton 3:fcd6d70e9694 83 /*
JoeShotton 3:fcd6d70e9694 84 if(pad.B_pressed() == true && length > size_inc) {
JoeShotton 3:fcd6d70e9694 85 length -= size_inc;
JoeShotton 3:fcd6d70e9694 86 printf("Lenght: %d\n", length);
JoeShotton 3:fcd6d70e9694 87 }
JoeShotton 3:fcd6d70e9694 88 */
JoeShotton 3:fcd6d70e9694 89
JoeShotton 3:fcd6d70e9694 90 /*
JoeShotton 3:fcd6d70e9694 91 body_x.insert(body_x.begin(), x_head); //sets first array element to head coordinates
JoeShotton 3:fcd6d70e9694 92 body_y.insert(body_y.begin(), y_head);
JoeShotton 3:fcd6d70e9694 93
JoeShotton 3:fcd6d70e9694 94 body_x.erase(body_x.begin()+length);
JoeShotton 3:fcd6d70e9694 95 body_y.erase(body_y.begin()+length);
JoeShotton 3:fcd6d70e9694 96 */
JoeShotton 3:fcd6d70e9694 97 /*
JoeShotton 3:fcd6d70e9694 98 if(pad.A_pressed() == true) {
JoeShotton 3:fcd6d70e9694 99 length += size_inc;
JoeShotton 3:fcd6d70e9694 100 //printf("Length: %d\n", length);
JoeShotton 3:fcd6d70e9694 101 body = new int*[length];
JoeShotton 3:fcd6d70e9694 102 for(int i = length + 1; i < length + size_inc + 1; i++) {
JoeShotton 3:fcd6d70e9694 103 body[i] = new int[2];
JoeShotton 3:fcd6d70e9694 104 body[i][0] = X_MAX + 1; //snake body starts outside the screen
JoeShotton 3:fcd6d70e9694 105 body[i][1] = 0;
JoeShotton 3:fcd6d70e9694 106 }
JoeShotton 3:fcd6d70e9694 107 */
eencae 0:b7f1f47bb26a 108
JoeShotton 4:ea3fa51c4386 109