jordan harper / Mbed 2 deprecated GameProject

Dependencies:   N5110 mbed

Embed: (wiki syntax)

« Back to documentation index

main.h File Reference

main.h File Reference

Header file containing functions prototypes, defines and global variables. More...

Go to the source code of this file.

Namespaces

namespace  button
 

sends digital signal to mbed when joystick is pressed, can interrupt at any point in code where there is a button flag


namespace  xPot
 

sends analog signal to mbed from X-axis of joystick


namespace  yPot
 

sends analog signal to mbed from Y-axis of joystick


namespace  lcd
 

recieves and sends data between LCD connections and mbed


namespace  power
 

PWM Output to LED to signal that the power is On/Off.


namespace  buz
 

PWM Output to Piezo Buzzer to play a song.


Typedefs

typedef struct JoyStick Joystick

Functions

Serial serial (USBTX, USBRX)
LocalFileSystem local ("local")
void calibrateJoystick ()
 reads default positions of the joystick to calibrate later readings.
void updateJoystick ()
 reads current joystick values relative to the calibrated centre value and calculates direction of joystick.
void clearCells ()
 Turns all cells on the display off.
void flagForWall ()
 flag function for moving wall to call later
void flagForWall2 ()
 flag function for moving wall to call later
void flagForWall3 ()
 flag function for moving wall to call later
void menu ()
 displays menu of options that can be selected with joystick
void playGame ()
 initiates game and detects collisions with walls
void setTime ()
 uses UNIX time to set time and date of Real Time Clock
void writeDataToFile ()
 writes data to on board Flash memory.
void BandVMenu ()
 menu for brightness of LCD and volume of buzzer
void brightness ()
 sets brightness of LCD
void volume ()
 sets volume of buzzer
void tone ()
 plays song using different frequencies of PWM through buzzer used to play gameplay music
void deadTone ()
 plays song using different frequencies of PWM through buzzer used to play a 'game over' tone
void readDataFromFile ()
 reads data from the on board Flash memory.
void scoreCheck ()
 checks current score against the highscore and decides whether to record it or not.
void flagForFlash ()
 flag function for when the game is over
void GameOverFlash ()
 displays "Game Over!" for 3 seconds uses a timer instead of wait() function to save power
void powerSave ()
 Puts mbed into sleep mode and powers down the LCD if the game is left for more than 20 seconds.
void Sleep ()
 puts mbed into sleep mode
void boundries ()
 rules to prevent player object going off the screen
void playerMovement ()
 moves player object on LCD screen to new position.
void fallingWalls ()
 sets different wall objects that move across the screen.
void instructions ()
 gives instructions on how to navigate in menu
void buttonFlag ()
 flag function for joystick button

Variables

int nx = 84
int ny = 48
int x = 0
int y = 0
int z = 30
int i = 24
int j = 42
int score = 0
int printFlag = 0
int FLAG = 0
int FLAG2 = 0
int FLAG3 = 0
int c = 0
int bright = 0
int vol = 0
int u = 0
int soundFlag = 1
int flashFlag = 0
int BFlag = 0
int sleepCounter = 0
int a = 0
int b = 47
int d = 30
int f = 0
int g = 0
int h = 24
int q = 83
int w = 0
int e = 24
float frequency [] = {880,880,0,0,440,880,0,0,440,880,600,1047,0,0,0,0,880,880,0,0,440,880,0,0,440,880,600,587,0,0,0,0,0}
float frequency2 [] = {600,600,400,400,200}
Ticker pollJoystick
Ticker wallMovement
Ticker wallMovement2
Ticker wallMovement3
Ticker flash
Joystick joystick

Detailed Description

Header file containing functions prototypes, defines and global variables.

See also:
"Joystick" by Craig Evans
Author:
Jordan Harper
Date:
April 2015

Definition in file main.h.


Typedef Documentation

typedef struct JoyStick Joystick

struct for Joystick

Definition at line 302 of file main.h.


Function Documentation

void BandVMenu (  )

menu for brightness of LCD and volume of buzzer

Parameters:
t- value of specific case
case0 - brightness option
case1 - volume option
case2 - instructions option

Definition at line 408 of file main.cpp.

void boundries (  )

rules to prevent player object going off the screen

Definition at line 752 of file main.cpp.

void brightness (  )

sets brightness of LCD

Parameters:
bright- value of specific case
case0 - sets LCD backlight to 60%
case1 - sets LCD backlight to 80%
case2 - sets LCD backlight to 90%
case3 - sets LCD backlight to 100%
case-1 - sets LCD backlight to 40%
case-2 - sets LCD backlight to 20%
case-3 - turns LCD backlight off

Definition at line 460 of file main.cpp.

void buttonFlag (  )

flag function for joystick button

Definition at line 93 of file main.cpp.

void calibrateJoystick (  )

reads default positions of the joystick to calibrate later readings.

Parameters:
joystick.x0- float value in X-axis to read
joystick.y0- float value in Y-axis to read
Returns:
a definition for the centre value of joystick

Definition at line 24 of file main.cpp.

void clearCells (  )

Turns all cells on the display off.

Parameters:
i- all cells in x direction on screen
j- all cells in y direction on screen
Returns:
a blank screen

Definition at line 65 of file main.cpp.

void deadTone (  )

plays song using different frequencies of PWM through buzzer used to play a 'game over' tone

Parameters:
l- variable to represent each frequency in the array

Definition at line 672 of file main.cpp.

void fallingWalls (  )

sets different wall objects that move across the screen.

each wall has one gap in it which the player must move through to survive. as the score increases, more walls are added to the screen making it more difficult to survive.

Definition at line 811 of file main.cpp.

void flagForFlash (  )

flag function for when the game is over

Definition at line 703 of file main.cpp.

void flagForWall (  )

flag function for moving wall to call later

Definition at line 76 of file main.cpp.

void flagForWall2 (  )

flag function for moving wall to call later

Definition at line 82 of file main.cpp.

void flagForWall3 (  )

flag function for moving wall to call later

Definition at line 88 of file main.cpp.

void GameOverFlash (  )

displays "Game Over!" for 3 seconds uses a timer instead of wait() function to save power

Definition at line 709 of file main.cpp.

void instructions (  )

gives instructions on how to navigate in menu

Definition at line 879 of file main.cpp.

LocalFileSystem local ( "local"   )

create local filesystem

void menu (  )

displays menu of options that can be selected with joystick

Parameters:
case0 - displays the "Play Game" option
case1 - displays the "Settings" option
case2 - displays the "Highscore" option
Returns:
a menu of options that can be selected to initiate other functions

Definition at line 98 of file main.cpp.

void playerMovement (  )

moves player object on LCD screen to new position.

if joystick direction is a diagonal the player object moves one space in y direction and one space in x direction. i.e. upRight direction would cause the player object to move up first, then to the right.

Definition at line 769 of file main.cpp.

void playGame (  )

initiates game and detects collisions with walls

Parameters:
i- x coordinate of player object
j- y coordinate of player object
m- value of specific case
case0 - displays YES option
case1 - displays restart question
case2 - displays NO option

Definition at line 166 of file main.cpp.

void powerSave (  )

Puts mbed into sleep mode and powers down the LCD if the game is left for more than 20 seconds.

this saves power. it can be turned back on again by pushing the joystick button.

Definition at line 725 of file main.cpp.

void readDataFromFile (  )

reads data from the on board Flash memory.

Definition at line 638 of file main.cpp.

void scoreCheck (  )

checks current score against the highscore and decides whether to record it or not.

this is done by scanning the text file saved to the on board Flash memory and then comparing it to the score that has been achieved after the current game is over.

Definition at line 689 of file main.cpp.

Serial serial ( USBTX  ,
USBRX   
)

Serial for debug

void setTime (  )

uses UNIX time to set time and date of Real Time Clock

void Sleep (  )

puts mbed into sleep mode

Definition at line 45 of file PowerControl.h.

void tone (  )

plays song using different frequencies of PWM through buzzer used to play gameplay music

Parameters:
u- variable to represent each frequency in the array

Definition at line 656 of file main.cpp.

void updateJoystick (  )

reads current joystick values relative to the calibrated centre value and calculates direction of joystick.

Parameters:
joystick.x- new float value in X-axis to read
joystick.y- new float value in Y-axis to read
joystick.button- state of joystick button to read
joystick.direction- calculated direction state of joystick
Returns:
direction of joystick

Definition at line 31 of file main.cpp.

void volume (  )

sets volume of buzzer

Parameters:
vol- value of specific case
case0 - sets PWM duty ratio to buzzer to 0.6
case1 - sets PWM duty ratio to buzzer to 0.8
case2 - sets PWM duty ratio to buzzer to 0.9
case3 - sets PWM duty ratio to buzzer to 1.0
case-1 - sets PWM duty ratio to buzzer to 0.4
case-2 - sets PWM duty ratio to buzzer to 0.2
case-3 - sets PWM duty ratio to buzzer to zero (MUTE)

Definition at line 545 of file main.cpp.

void writeDataToFile (  )

writes data to on board Flash memory.

data such as the score and date (if it is better than the previous highscore) is printed to a text file.

Definition at line 625 of file main.cpp.


Variable Documentation

int a = 0

wall starts from the coordinates (0,47)

Definition at line 96 of file main.h.

int b = 47

wall starts from the coordinates (0,47)

Definition at line 97 of file main.h.

int BFlag = 0

flag for joystick button

Definition at line 91 of file main.h.

int bright = 0

initial case for brightness function in switch loop

Definition at line 81 of file main.h.

int c = 0

initial value for position of option in menu

Definition at line 79 of file main.h.

int d = 30

gap in wall is near the middle of screen

Definition at line 98 of file main.h.

int e = 24

gap in wall is near the top left corner

Definition at line 104 of file main.h.

int f = 0

wall starts from the coordinates (0,0)

Definition at line 99 of file main.h.

int FLAG = 0

initial value for flag that are used for wall movement

Definition at line 75 of file main.h.

int FLAG2 = 0

initial value for flag that are used for wall movement 2

Definition at line 76 of file main.h.

int FLAG3 = 0

initial value for flag that are used for wall movement 3

Definition at line 77 of file main.h.

Ticker flash

timer for "Game Over!" phrase and sleep intterupt

Definition at line 114 of file main.h.

int flashFlag = 0

flag for calling "Game Over!" phrase

Definition at line 89 of file main.h.

float frequency[] = {880,880,0,0,440,880,0,0,440,880,600,1047,0,0,0,0,880,880,0,0,440,880,0,0,440,880,600,587,0,0,0,0,0}

frequency array for gameplay song

Definition at line 106 of file main.h.

float frequency2[] = {600,600,400,400,200}

frequency array for gameover song

Definition at line 107 of file main.h.

int g = 0

wall starts from the coordinates (0,0)

Definition at line 100 of file main.h.

int h = 24

gap in wall is near the top left corner

Definition at line 101 of file main.h.

int i = 24

initial coordinates for player object (24,42)

Definition at line 65 of file main.h.

int j = 42

initial coordinates for player object (24,42)

Definition at line 66 of file main.h.

create struct variable

Definition at line 314 of file main.h.

int nx = 84

screen is 84 pixels across

Definition at line 56 of file main.h.

int ny = 48

by 48 pixels downwards

Definition at line 57 of file main.h.

Ticker pollJoystick

timer to regularly read the joystick

Definition at line 110 of file main.h.

int printFlag = 0

print flag initial value

Definition at line 72 of file main.h.

int q = 83

wall starts from the coordinates (83,0)

Definition at line 102 of file main.h.

int score = 0

initial value for the score at beginning of game

Definition at line 69 of file main.h.

int sleepCounter = 0

initial value set for timer to save power

Definition at line 93 of file main.h.

int soundFlag = 1

flag for toggling mute

Definition at line 87 of file main.h.

int u = 0

initial value for u (used to select next frequency of PWM in song)

Definition at line 85 of file main.h.

int vol = 0

initial case for volume function in switch loop

Definition at line 83 of file main.h.

int w = 0

wall starts from the coordinates (83,0)

Definition at line 103 of file main.h.

Ticker wallMovement

timers for moving the walls

Definition at line 111 of file main.h.

Ticker wallMovement2

timers for moving the walls

Definition at line 112 of file main.h.

Ticker wallMovement3

timers for moving the walls

Definition at line 113 of file main.h.

int x = 0

wall starts from the coordinates (0,0)

Definition at line 60 of file main.h.

int y = 0

wall starts from the coordinates (0,0)

Definition at line 61 of file main.h.

int z = 30

gap in the wall starts near the middle of the screen

Definition at line 62 of file main.h.