ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

main.cpp

Committer:
el17arm
Date:
2019-04-16
Revision:
42:d81c008b0436
Parent:
41:0cf320f73424
Child:
44:e29458976114

File content as of revision 42:d81c008b0436:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Andrew Milner
Username: el17arm
Student ID Number: 201162219
Date: 18/03/19
*/


#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Gameengine.h"

Gameengine game;
Gamepad pad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
AnalogIn pot0(PTB2);

BusOut oxygen(PTA1, PTA2, PTC2);
BusOut lives(PTC3, PTC4, PTD3);

void contrast();
void init();
void start_screen();
void leds();
void render();
void restart();
void button_a();

int main()
{
    init();
    start_screen();


    while (1) {

        contrast();
        render();
        game.update(lcd, pad);
        restart();
        wait(0.1);
        
        

    }

}

void init()
{
    lcd.init();
    lcd.normalMode();      // normal colour mode
    lcd.refresh();
    lcd.setBrightness(1.0);
    pad.init();
    pad.leds_off();
    contrast();
    game.game_init();
}

void render()
{
    game.draw_l1(lcd, pad);
    game.draw_l2(lcd, pad);
    leds();
}

void contrast()
{
    lcd.refresh();
    float con = pot0.read();
    lcd.setContrast(con);
    lcd.clear();
}

void start_screen()
{
    lcd.printString("*MANIC MILNER*",0,1);
    lcd.printString(" Press start! ",0,4);
    lcd.refresh();
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
    }
}

void restart()
{
    if (game.game_over() == true) {
        lcd.clear();
        game.get_score(lcd);
        lcd.printString("Game Over! ",12,0);
        lcd.printString("Score ",4,2);
        lcd.printString("Press reset to try again! ",0,4);
        lcd.printString("try again! ",16,5);
        wait(1);
    }
}

void leds()
{
    int l_leds[4]  = {0b111,0b110,0b100,0b000};
    int r_leds[4]  = {0b111,0b110,0b100,0b000};
    
    oxygen = l_leds[game.oxygen_leds()];
    lives = r_leds[game.lives_leds()];
}