Zachary Reyes / Lab4_gnuarmeclipse_lpc1768

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <stdio.h>
00003 #include "Speaker.h"
00004 #include "PinDetect.h"
00005 #include "BuzzyGraphics.h"
00006 #include "uLCD_4DGL.h"
00007 
00008 #include "Buzzy.h"
00009 #include "Ghosts.h"
00010 ////////////////////////////////////////
00011 // Setup instance of LCD display
00012 uLCD_4DGL guLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
00013 ////////////////////////////////////////
00014 // Setup instances of push button pins
00015 PinDetect gPB_left(p16); 
00016 PinDetect gPB_right(p17); 
00017 PinDetect gPB_up(p19);
00018 PinDetect gPB_down(p18);
00019 // Create Buzzy and Ghosts
00020 Buzzy gBuzzy;
00021 Ghosts gGhosts[NUM_GHOSTS];
00022 // Variable indicates if game is paused or running
00023 int gGameState = GAME_PAUSED;
00024 // Declare and initialize the speaker
00025 Speaker gSpeakerOut(p21);
00026 
00027 ////////////////////////////////////////////////////////
00028 // This is the maze that changes as the game is played
00029 char gDynaMaze[MAZE_NUM_ROW][MAZE_NUM_COL]; 
00030 
00031 //////////////////////////
00032 // Prototype functions
00033 void DrawMaze();
00034 
00035 //////////////////////////////////////////////////////////////////////
00036 // Interrupt routine
00037 // used to output next analog sample whenever a timer interrupt occurs
00038 void Sample_timer_interrupt(void)
00039 {
00040     // Call speaker function to play next value
00041 }
00042 //---------------------------------------------------------------------------------------------------
00043 // Callback routine is interrupt activated by a debounced pb_left hit
00044 void pb_left_hit_callback (void)
00045 {
00046     // Update game state and tell Buzzy to go left
00047 }
00048 //---------------------------------------------------------------------------------------------------
00049 // Callback routine is interrupt activated by a debounced pb_right hit
00050 void pb_right_hit_callback (void)
00051 {
00052     // Update game state and tell Buzzy to go left
00053 }
00054 //---------------------------------------------------------------------------------------------------
00055 // Callback routine is interrupt activated by a debounced pb_up hit
00056 void pb_up_hit_callback (void)
00057 {
00058     // Update game state and tell Buzzy to go left
00059 }
00060 //---------------------------------------------------------------------------------------------------
00061 // Callback routine is interrupt activated by a debounced pb_down hit
00062 void pb_down_hit_callback (void)
00063 {
00064     // Update game state and tell Buzzy to go left
00065 }
00066 //---------------------------------------------------------------------------------------------------
00067 int main()
00068 {
00069         
00070     // Setup push buttons
00071     gPB_left.mode(PullUp);
00072     gPB_right.mode(PullUp);
00073     gPB_up.mode(PullUp);
00074     gPB_down.mode(PullUp);
00075     // Delay for initial pullup to take effect
00076     wait(.01);
00077     // Setup Interrupt callback functions for a pb hit
00078     gPB_left.attach_deasserted(&pb_left_hit_callback);
00079     gPB_right.attach_deasserted(&pb_right_hit_callback);
00080     gPB_up.attach_deasserted(&pb_up_hit_callback);
00081     gPB_down.attach_deasserted(&pb_down_hit_callback);
00082     // Setup speaker
00083     gSpeakerOut.period(1.0/200000.0);  
00084     // set up a timer to be used for sample rate interrupts
00085     Ticker Sample_Period;      
00086     Sample_Period.attach(&Sample_timer_interrupt, 1.0/(20000.0));
00087 
00088     //Setup LCD display
00089     guLCD.display_control(PORTRAIT);
00090     guLCD.background_color(BLACK);
00091     guLCD.cls();
00092     guLCD.baudrate(BAUD_3000000); //jack up baud rate to max for fast display
00093     wait(1.0);
00094   
00095     // Start sampling pb inputs using interrupts
00096     gPB_left.setSampleFrequency();
00097     gPB_right.setSampleFrequency();
00098     gPB_up.setSampleFrequency();
00099     gPB_down.setSampleFrequency();
00100     //////////////////////////////////////
00101     // Everything should be ready to start playing the game.
00102     while(1)
00103     {
00104         guLCD.cls();
00105         // Ask the user if they would like to play a game. 
00106  
00107         // Wait for a button to be pressed
00108 
00109         guLCD.cls();
00110         // Initialize needed parts
00111         
00112         // Reset the Ghosts and Buzzy states
00113 
00114         // Start up new game
00115         // Play introduction sounds while drawing the Maze
00116         gSpeakerOut.SwitchSound(Speaker::BEGIN);
00117         DrawMaze();  
00118         // Start Game loop
00119         while (gGameState == GAME_RUNNING)
00120         {
00121             // Move Buzzy and any active ghosts
00122             // Check to see if Buzzy has eaten all the honey drops
00123             // Break out of loop if all honey drops are consumed
00124             wait(0.001);
00125         }
00126 
00127         gGameState = GAME_PAUSED;
00128     }
00129 
00130 } //end main