ELEC2645 (2015/16) / Mbed 2 deprecated frdm_Asteroids

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.

Data Structures

struct  State

Namespaces

namespace  lcd
 

This allows the mbed to interface with the N5110 screen.


namespace  b1
 

Sets up a button that allows for interrupts to be called on pin PTB19.


namespace  b2
 

Sets up a button that allows for interrupts to be called on pin PTB18.


namespace  xPot
 

Sets up the potentiometer that determines the horizontal position of the joystick.


namespace  yPot
 

Sets up the potentiometer that determines the vertical position of the joystick.


namespace  ticker
 

A ticker that is attatched to a time based interrupt to allow the screen to periodically refresh.


namespace  timer
 

A timer that is used as the seed to generate a random number for asteroid creation.


Functions

void b1_isr ()
 A function which alters the b1 flag from 0 to 1 when an interrupt occurs.
void b2_isr ()
 A function which alters the b2 flag from 0 to 1 when an interrupt occurs.
void timer_isr ()
 A function which alters the timer flag from 0 to 1 when the time interrupt occurs.
void calibrateJoystick ()
 Reads the initial positon of the joystick and sets this as centered.
void updateJoystick ()
 Compares the current positon of the joystick to the centred position of the joystick and calculates which way the joystick has been pushed.
void game ()
 The main game function in it the.
void shoots ()
 A function that reads the ships direction and fires a bullet in that direction.
void asteroidMove ()
 A function that using random numbers determines which size asteroid to generate and from which direction The function also checks to see if there is a bullet or ship in front of it, if there isn't the asteroid moves forward.
void checkbullet ()
 checks to see if the bullet has left the screen without hitting anything if it has the bullet is erased

Variables

volatile int g_b1_flag = 0
volatile int g_b2_flag = 0
volatile int g_timer_flag = 0
int score = 0
int bullet_number = 0
int shipDirection = 0
int game_over = 0
int printFlag = 0
int state = 1
int direction = UP
int settings = 0
STyp fsm [8]

Detailed Description

Header file containing functions prototypes, defines and global variables.

Shows examples of creating Doxygen documentation. Revision 1.0.

Author:
Martin Woodhams
Date:
March 2015

Definition in file main.h.


Function Documentation

void asteroidMove (  )

A function that using random numbers determines which size asteroid to generate and from which direction The function also checks to see if there is a bullet or ship in front of it, if there isn't the asteroid moves forward.

the random variable number is used to assign the type of asteroid

Definition at line 330 of file main.cpp.

void b1_isr (  )

A function which alters the b1 flag from 0 to 1 when an interrupt occurs.

Definition at line 122 of file main.cpp.

void b2_isr (  )

A function which alters the b2 flag from 0 to 1 when an interrupt occurs.

Definition at line 128 of file main.cpp.

void calibrateJoystick (  )

Reads the initial positon of the joystick and sets this as centered.

Definition at line 134 of file main.cpp.

void checkbullet (  )

checks to see if the bullet has left the screen without hitting anything if it has the bullet is erased

Definition at line 891 of file main.cpp.

void game (  )

The main game function in it the.

from the FSM the next direction is chosen and the code loops through the appropriate array to face the ship in that direction

Definition at line 730 of file main.cpp.

void shoots (  )

A function that reads the ships direction and fires a bullet in that direction.

The function also checks any exsisting bullets and moves them in the appropriate direction.

Definition at line 172 of file main.cpp.

void timer_isr (  )

A function which alters the timer flag from 0 to 1 when the time interrupt occurs.

Definition at line 116 of file main.cpp.

void updateJoystick (  )

Compares the current positon of the joystick to the centred position of the joystick and calculates which way the joystick has been pushed.

based on the value calculated the joystick is given an overall direction

Definition at line 141 of file main.cpp.


Variable Documentation

int bullet_number = 0

A variable that keeps count of how many bullets are on screen

Definition at line 83 of file main.h.

int direction = UP

the initial direction of the ship is to travel UP

Definition at line 88 of file main.h.

STyp fsm[8]
Initial value:
 {
    {0,{0,1,1,1,1,7,7,7,0}},
    {1,{0,1,2,2,2,2,0,0,1}},
    {2,{1,1,2,3,3,3,3,1,2}},
    {3,{2,2,2,3,4,4,4,4,3}},
    {4,{5,3,3,3,4,5,5,5,4}},
    {5,{6,6,4,4,4,5,6,6,5}},
    {6,{7,7,7,5,5,5,6,7,6}},
    {7,{0,0,0,0,6,6,6,7,7}},

}

The FSM has 9 possible inputs and 8 possible outcomes the inputs are taken from the joystick direction and go as following UP = 0, UPRIGHT = 1, RIGHT = 2, DOWNRIGHT = 3, DOWN = 4, DOWNLEFT = 5, LEFT = 6, UPLEFT = 7, STAY = 8 The ships direction follows the same pattern and the FSM aims to get the ship to face that direction in the quickest way possible If the joystick is pushed in a direction completly opposite to the ship the ship will spin clockwise

Definition at line 99 of file main.h.

volatile int g_b1_flag = 0

A global flag which is called on when the interrupt on b1 is called

Definition at line 79 of file main.h.

volatile int g_b2_flag = 0

A global flag which is called on when the interrupt on b2 is called

Definition at line 80 of file main.h.

volatile int g_timer_flag = 0

A global flag which is called on when the timer flags

Definition at line 81 of file main.h.

int game_over = 0

A variable that determines when the game is over

Definition at line 85 of file main.h.

int printFlag = 0

a flag to show that the joystick can be read

Definition at line 86 of file main.h.

int score = 0

A variable that keeps track of the score the player is achieving

Definition at line 82 of file main.h.

int settings = 0

aa flag to tell if the settings option has been selected

Definition at line 89 of file main.h.

int shipDirection = 0

A variable determined by the FSM, this variable chooses which ship array is displayed and which direction bullets are shot

Definition at line 84 of file main.h.

int state = 1

set initial state of the FSM state 1 UP

Definition at line 87 of file main.h.