A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

main.cpp

Committer:
el13drt
Date:
2015-04-17
Revision:
15:ff3eb0091453
Parent:
14:c2c969e1c6e8
Child:
16:93ae2f311fd8

File content as of revision 15:ff3eb0091453:

/**
@file main.cpp
@brief Program implementation
*/

#include "mbed.h"
#include "N5110.h"
#include "beep.h"
#include "tower.h"
#include "PowerControl/PowerControl.h"

#include <ctime>
#include <cstdlib>

int main()
{
    ledR = 1;//power LED on
    randomise();//randomises falling hazards (initial values only)
    calibrateJoystick();//get centred values of joystick
    pollJoystick.attach(&updateJoystick,1.0/10.0);//read joystick 10 times per second

    lcd.init();//initialise screen
    welcome();//welcome screen
    lcd.clear();//clear pixels

    int exitFlag = 0;//exit flag
    int mainOption = 0;//counter for main menu
    int exitOption = 0;//counter for exit menu
    
    buttonA.mode(PullDown);
    buttonB.mode(PullDown);
    
    timer.attach(&timerExpiredA, 0.1);//checks state of buttonA
    timer2.attach(&timerExpiredB, 0.1);//checks state of buttonB
    
    while(1) {
        drawMainMenu();//draws main menu
        mainMenu(mainOption);//presents main menu options

        // if 'Play Game' selected
        if ((mainOption == 0)&&(buttonFlagA)) {
            buttonFlagA = 0;
            game(exitFlag, exitOption);//actual game
        }
        // if 'Scores' selected
        if((mainOption == 1)&&(buttonFlagA)) {
            buttonFlagA = 0;
            scores();
        }
        // if 'option' selected
        if((mainOption == 2)&&(buttonFlagA)) {
            buttonFlagA = 0;
            optionsMenu();
        }
        sleep();
    }
}