testing documentation

Dependencies:   mbed ll16j23s_test_docs

Committer:
JoeShotton
Date:
Sat May 23 17:16:44 2020 +0000
Revision:
5:06fa7674622a
Parent:
4:ea3fa51c4386
Child:
6:6c9453397f4a
Implemented magnetometre to seed random function

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 5:06fa7674622a 29 FXOS8700CQ mag(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 5:06fa7674622a 35 snake.init(mag);
JoeShotton 1:985dfa6cee28 36
JoeShotton 1:985dfa6cee28 37 float speed = 0.5;
JoeShotton 3:fcd6d70e9694 38
JoeShotton 1:985dfa6cee28 39 int fps = 25;
JoeShotton 1:985dfa6cee28 40 int frame_t = 1000/fps;
JoeShotton 2:86b67b492cbc 41 bool death = false;
JoeShotton 3:fcd6d70e9694 42
JoeShotton 3:fcd6d70e9694 43 //int length = 10; //intial snake size
JoeShotton 3:fcd6d70e9694 44 //int size_inc = 5; //how much longer the snake gets due to food
JoeShotton 1:985dfa6cee28 45
JoeShotton 1:985dfa6cee28 46
JoeShotton 3:fcd6d70e9694 47 //int d = 0; //direction starts in centre
JoeShotton 3:fcd6d70e9694 48 //int state = 0; //first state is centre of joystick
JoeShotton 3:fcd6d70e9694 49
JoeShotton 3:fcd6d70e9694 50 /*
JoeShotton 1:985dfa6cee28 51 Dir fsm[5] = {
JoeShotton 1:985dfa6cee28 52 {0, 0, 0, {0,1,2,3,4}}, // Centred
JoeShotton 1:985dfa6cee28 53 {1, 0, -1, {1,1,2,1,4}}, // North, will not go to centre or south
JoeShotton 1:985dfa6cee28 54 {2, 1, 0, {2,1,2,3,2}}, // East, will not go to centre or west
JoeShotton 1:985dfa6cee28 55 {3, 0, 1, {3,3,2,3,4}}, // South, will not go to centre or north
JoeShotton 1:985dfa6cee28 56 {4, -1, 0, {4,1,4,3,4}} // West, will not go to centre or east
JoeShotton 1:985dfa6cee28 57 };
JoeShotton 3:fcd6d70e9694 58 */
JoeShotton 4:ea3fa51c4386 59 while(death == false){
JoeShotton 1:985dfa6cee28 60
JoeShotton 4:ea3fa51c4386 61 //printf("Running!");
JoeShotton 3:fcd6d70e9694 62
JoeShotton 1:985dfa6cee28 63 speed = pad.read_pot2();
JoeShotton 1:985dfa6cee28 64
JoeShotton 4:ea3fa51c4386 65 lcd.clear();
JoeShotton 4:ea3fa51c4386 66 snake.move_body(pad, lcd, death);
JoeShotton 4:ea3fa51c4386 67 lcd.setContrast(0.4);
JoeShotton 4:ea3fa51c4386 68 lcd.refresh();
JoeShotton 4:ea3fa51c4386 69 wait_ms(500/(5+snake.score));
JoeShotton 4:ea3fa51c4386 70 }
JoeShotton 4:ea3fa51c4386 71 }
JoeShotton 4:ea3fa51c4386 72
JoeShotton 3:fcd6d70e9694 73 /* if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) {
JoeShotton 2:86b67b492cbc 74 // checks infront of head to see if pixel is set
JoeShotton 2:86b67b492cbc 75 // due to the size of the head, there is an offset for the check for North and Eastward directions
JoeShotton 2:86b67b492cbc 76 death = true;
JoeShotton 2:86b67b492cbc 77 pad.led(1,0.9);
JoeShotton 2:86b67b492cbc 78 } else {
JoeShotton 2:86b67b492cbc 79 death = false;
JoeShotton 2:86b67b492cbc 80 pad.led(1,0.0);
JoeShotton 2:86b67b492cbc 81 }
JoeShotton 3:fcd6d70e9694 82 */
JoeShotton 3:fcd6d70e9694 83
JoeShotton 3:fcd6d70e9694 84 /*
JoeShotton 3:fcd6d70e9694 85 if(pad.B_pressed() == true && length > size_inc) {
JoeShotton 3:fcd6d70e9694 86 length -= size_inc;
JoeShotton 3:fcd6d70e9694 87 printf("Lenght: %d\n", length);
JoeShotton 3:fcd6d70e9694 88 }
JoeShotton 3:fcd6d70e9694 89 */
JoeShotton 3:fcd6d70e9694 90
JoeShotton 3:fcd6d70e9694 91 /*
JoeShotton 3:fcd6d70e9694 92 body_x.insert(body_x.begin(), x_head); //sets first array element to head coordinates
JoeShotton 3:fcd6d70e9694 93 body_y.insert(body_y.begin(), y_head);
JoeShotton 3:fcd6d70e9694 94
JoeShotton 3:fcd6d70e9694 95 body_x.erase(body_x.begin()+length);
JoeShotton 3:fcd6d70e9694 96 body_y.erase(body_y.begin()+length);
JoeShotton 3:fcd6d70e9694 97 */
JoeShotton 3:fcd6d70e9694 98 /*
JoeShotton 3:fcd6d70e9694 99 if(pad.A_pressed() == true) {
JoeShotton 3:fcd6d70e9694 100 length += size_inc;
JoeShotton 3:fcd6d70e9694 101 //printf("Length: %d\n", length);
JoeShotton 3:fcd6d70e9694 102 body = new int*[length];
JoeShotton 3:fcd6d70e9694 103 for(int i = length + 1; i < length + size_inc + 1; i++) {
JoeShotton 3:fcd6d70e9694 104 body[i] = new int[2];
JoeShotton 3:fcd6d70e9694 105 body[i][0] = X_MAX + 1; //snake body starts outside the screen
JoeShotton 3:fcd6d70e9694 106 body[i][1] = 0;
JoeShotton 3:fcd6d70e9694 107 }
JoeShotton 3:fcd6d70e9694 108 */
eencae 0:b7f1f47bb26a 109
JoeShotton 4:ea3fa51c4386 110