Dependencies:   mbed

main.cpp

Committer:
sdlashmar
Date:
2020-05-21
Revision:
7:c67a5c6a874f
Parent:
6:964cc4896627
Child:
8:1e4182ebb063

File content as of revision 7:c67a5c6a874f:

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

Name:Samuel Lashmar
Username:el17sdl
Student ID Number:201170334
Date:04/03/20
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "SnakeHead.h"
#include "SnakeTail.h"


// objects
Gamepad pad;
N5110 lcd;
SnakeHead head;
SnakeTail tail;

void welcome();
void init();


int main()
{
    int fps = 6;
    //initialise objects
    init();
    head.init(1,3);
    
    //render first frame 
    
    welcome();
    wait(3.0);
    
    lcd.clear();
    head.draw(lcd);
    lcd.refresh();
    
    while(1) {
    /*
    if (_d == N) {
        printf("North\n");
    } else if (_d == NE) {
        printf("North East\n"); 
    } else if (_d == E) {
        printf("East\n");
    } else if (_d == SE) {
        printf("South East\n");
    } else if (_d == S) {
        printf("South\n");
    } else if (_d == SW) {
        printf("South West\n");
    } else if (_d == W) {
        printf("West\n");
    } else if (_d == NW) {
        printf("North West\n");
    } else {
        printf("Centre\n");
        };*/
        /*if (pad.A_pressed() == true) {
            printf("start pressed\n");
        } else if (pad.A_pressed() == false) {
            printf("start not pressed\n");
            }*/
        Direction _d = pad.get_direction();
        head.change_direction(_d);
        //tail.set_length(2);
        Vector2D headPos = head.get_pos();
        head.update();
        //tail.update(headPos);
        lcd.clear();
        head.draw(lcd);
        //tail.draw(lcd);
        //tail.draw_tail(lcd, head, _d); 
        lcd.refresh();
        
        
        
        
        wait(1.0f/fps);
        }
        
        
}



void welcome() {
    
    lcd.printString("     SNAKE!    ",0,1);  
    lcd.refresh();
     
    /* wait flashing LEDs until start button is pressed (start pressed function does not seem ot be working as expected 
    while ( pad.start_pressed() == false) {
        lcd.setContrast( pad.read_pot1());
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    } */
 
}

void init() {
    
    lcd.init();
    pad.init();
}