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-30
Revision:
51:df3bab1d6926
Parent:
46:613eabb6ea86
Child:
52:bb2acf0e248a

File content as of revision 51:df3bab1d6926:

/**
@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()
{
    ledP = 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
    drawWelcome();//welcome screen
    lcd.clear();//clear pixels
    buttonA.mode(PullDown);//pull down buttonA
    buttonB.mode(PullDown);//pull down buttonB

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

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