My 2645 project Chenyu Li 200985958

Dependencies:   N5110 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.h Source File

main.h

Go to the documentation of this file.
00001 /**
00002 @file main.h
00003 @brief Header file containing functions prototypes, defines and and global variables.
00004 @brief Shows examples of creating Doxygen documentation.
00005 @brief Revision 1.0.
00006 @author Chenyu Li(John Lee) SID: 200985958.
00007 @data May 2016
00008 */
00009 
00010 #ifndef MAIN_H
00011 #define MAIN_H
00012 
00013 #include "mbed.h"
00014 
00015 #include "N5110.h" ///head file for N5110 in order to use the code set in N5110.
00016 #include <stdio.h> ///head file for random number.
00017 #include <stdlib.h> ///head file for random number.
00018 #define DIRECTION_TOLERANCE 0.05 /// change this to alter tolerance of joystick direction 
00019 
00020 
00021 ///VCC,SCE,RST,D/C,MOSI,SCLK,LED
00022 /**
00023 @namespace N5110_lcd
00024 @brief lcd display
00025 */
00026 N5110 lcd(PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
00027 /// Can also power (VCC) directly from VOUT (3.3 V) -
00028 /// Can give better performance due to current limitation from GPIO pin
00029 
00030 /**
00031 @namespace buzzer
00032 @brief buzzer connection
00033 */
00034 PwmOut buzzer(PTA2); ///set PwmOut out as the buzzer
00035 /**
00036 @namespace button
00037 @brief button connection
00038 */
00039 InterruptIn button(PTB18);/// set button as an interrupt in
00040 /**
00041 @namespace buttonjoystick
00042 @brief buttonjoystick connection
00043 */
00044 DigitalIn buttonjoystick(PTB11);/// connections for joystick
00045 /**
00046 @namespace xPot
00047 @brief joystick movement in x-axis.
00048 */
00049 AnalogIn xPot(PTB3);/// connections for joystick
00050 /**
00051 @namespace yPot
00052 @brief joystick movement in y-axis.
00053 */
00054 AnalogIn yPot(PTB2);/// connections for joystick
00055 
00056 Ticker pollJoystick;/// timer to regularly read the joystick
00057 Ticker bullet;/// set 'bullet' as a ticker (not used currently)
00058 Ticker enermy;/// set 'enermy' as a ticker (not used currently)
00059 
00060 Serial serial(USBTX,USBRX);/// Serial for debug
00061 /**
00062 create enumerated type (0,1,2,3 etc. for direction)
00063 could be extended for diagonals etc.
00064 */
00065 enum DirectionName {
00066     UP,
00067     DOWN,
00068     LEFT,
00069     RIGHT,
00070     CENTRE,
00071     UNKNOWN
00072 };
00073 
00074 typedef struct JoyStick Joystick;/// struct for Joystick
00075 
00076 struct JoyStick {
00077     float x;    /// current x value
00078     float x0;   /// 'centred' x value
00079     float y;    /// current y value
00080     float y0;   /// 'centred' y value
00081     int buttonjoystick; /// button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
00082     DirectionName direction;  /// current direction
00083 };
00084 
00085 Joystick joystick;/// create struct variable
00086 int printFlag = 0;/*!< set the printFlag to 0*/
00087 
00088 int enermyFlag  = 0;/*!< set the enermyFlag to 0*/
00089 int bulletFlag  = 0;/*!< set the bulletFlag to 0*/
00090 
00091 // function prototypes
00092 /**
00093 initialize the position of the joystick.
00094 */
00095 void calibrateJoystick();
00096 /**
00097 read the current joystick value.
00098 */
00099 void updateJoystick();
00100 
00101 void createbullet();
00102 void createenermy();
00103 /**
00104 return back the button_isr value.
00105 */
00106 void button_isr();
00107 
00108 int status  =1;/*!< set the status to 0*/
00109 
00110 volatile int g_button_flag = 0;/// set the original value of "g_button_flag" equals to 0.
00111 
00112 ///set "wall", "hit", "bullethit" as a boolean value. 
00113 bool wall = false;
00114 bool hit = false;
00115 bool bullethit = false;
00116 
00117 #endif