ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el17sdl_v2

Dependencies:   mbed

main.cpp

Committer:
sdlashmar
Date:
2020-05-14
Revision:
5:256e5e0b6cd7
Parent:
4:c5addc5475d3
Child:
6:964cc4896627

File content as of revision 5:256e5e0b6cd7:

/* 
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;
BusIn input(PTC5, PTC9, PTC7);
SnakeHead head;
SnakeTail tail;

void welcome();


int main()
{
    
    lcd.init();
    welcome();
    pad.init(); //display welcome age on start up 
    input.mode(PullUp);
    while(1) {
    /*Direction _d = pad.get_direction();
    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");
        };*/
    int state = input; //creates an integer number from button input
    printf("state: %d\n", state);
    //switch state based on button presses 
    switch(state) {
        case 3:
            
            head.init(1,3);
           
            
            
            while(1) {
                lcd.clear();
                head.draw(lcd);
                Direction _d = pad.get_direction();
                //printf("Stick direction: %s", d);
                head.change_direction(_d);
                head.update();
                Vector2D headPos = head.get_pos();
                //printf("pos x = %i\n", headPos.x);
                tail.set_length(15);
                tail.draw_tail(lcd, headPos);
                
                lcd.refresh();
                wait(0.5);
            }
            break;
        case 5:
            lcd.clear();
            lcd.printString("High Scores",0,3);
            lcd.refresh();
            break;
        case 6: 
            lcd.clear();
            lcd.printString("How to play",0,3);
            lcd.refresh();
            break;
                }
        }
    
}



void welcome() {
    lcd.printString("SNAKE", 28, 0);
    lcd.printString("A.Play Game", 0, 1);
    lcd.printString("B.Highscores", 0, 2);
    lcd.printString("X.How to Play", 0, 3);
    lcd.refresh();
}