testing documentation

Dependencies:   mbed ll16j23s_test_docs

main.cpp

Committer:
JoeShotton
Date:
2020-05-20
Revision:
3:fcd6d70e9694
Parent:
2:86b67b492cbc
Child:
4:ea3fa51c4386

File content as of revision 3:fcd6d70e9694:

/* 
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name: Joe Shotton
Username: ll16j23s
Student ID Number: 201127267
Date: 4/4/20
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "FXOS8700CQ.h"
#include "SnakeEngine.h"
#include <vector>
#include <cstdlib>

#define X_MAX       84
#define Y_MAX       48

// objects
Gamepad pad;
N5110 lcd;
SnakeEngine snake;
FXOS8700CQ device(I2C_SDA,I2C_SCL);

int main() {
    
    lcd.init();
    pad.init();
    
    float speed = 0.5;
    int cell_size = 2;
    
    int fps = 25;
    int frame_t = 1000/fps;
    bool death = false;

    //int length = 10; //intial snake size
    //int size_inc = 5; //how much longer the snake gets due to food
    
    
    //int d = 0; //direction starts in centre
    //int state = 0; //first state is centre of joystick

/*    
    Dir fsm[5] = {
        {0, 0,  0, {0,1,2,3,4}},  // Centred
        {1, 0, -1, {1,1,2,1,4}},  // North, will not go to centre or south
        {2, 1,  0, {2,1,2,3,2}},  // East, will not go to centre or west
        {3, 0,  1, {3,3,2,3,4}},  // South, will not go to centre or north
        {4, -1, 0, {4,1,4,3,4}}   // West, will not go to centre or east
    };
*/
    while(1){
        
        printf("Running!");
        
        speed = pad.read_pot2();
        
/*
        if ((x_head % cell_size) + (y_head % cell_size) == 0) {   // only allows changing movement when the snake is cell-aligned
            d = pad.get_cardinal();          // gets joystick cardinal direction: 0 for centre, 1 - 4 for NESW respectively
            state = fsm[state].nextState[d]; // adjusts direction fsm state based on direction
        }
*/        
        /*
        x_head += fsm[state].delta_x; // increments x value based on fsm state value
        y_head += fsm[state].delta_y; // increments y value based on fsm state value
            
        x_head = ((x_head % X_MAX) + X_MAX)% X_MAX; // wraps x back to within range 0-83
        y_head = ((y_head % Y_MAX) + Y_MAX)% Y_MAX; // wraps y back to within range 0-83
        */
/*        if ((lcd.getPixel(x, y) == 1 && ((state == 1) || (state == 4))) || (lcd.getPixel(x+1, y+1) == 1 && ((state == 2) || (state == 3)))) {
        // checks infront of head to see if pixel is set
        // due to the size of the head, there is an offset for the check for North and Eastward directions
            death = true;
            pad.led(1,0.9);
        } else {
            death = false;
            pad.led(1,0.0);
        }
*/        
        
 /*       
        if(pad.B_pressed() == true && length > size_inc) {
            length -= size_inc;
            printf("Lenght: %d\n", length);
        }
*/  
        
/*        
        body_x.insert(body_x.begin(), x_head); //sets first array element to head coordinates
        body_y.insert(body_y.begin(), y_head);
        
        body_x.erase(body_x.begin()+length);
        body_y.erase(body_y.begin()+length);
*/        
/*
        if(pad.A_pressed() == true) {
            length += size_inc;
            //printf("Length: %d\n", length);
            body = new int*[length];
              for(int i = length + 1; i < length + size_inc + 1; i++) {
                body[i] = new int[2];
                body[i][0] = X_MAX + 1;        //snake body starts outside the screen
                body[i][1] = 0;
            }   
*/        
        
        lcd.clear();
        lcd.setContrast(0.5);
        
        //for(int i = 0; i < length; i++) {
            //lcd.drawRect(body_x[i],body_y[i],cell_size,cell_size,FILL_BLACK);
        //}
        
        //lcd.drawRect(10,10,6,6,FILL_BLACK);
        lcd.refresh();
        wait_ms(25/speed);
    }   
}