meurig phillips snake game - accidentally published to my account instead of to the group!
Dependencies: Joystick N5110 SDFileSystem beep fsmMenu mbed
Fork of SnakeProjectRev1 by
Diff: main.h
- Revision:
- 21:e03461ea23e9
- Parent:
- 19:8907a82ebe09
- Child:
- 22:195d66c61bf3
--- a/main.h Thu May 05 13:31:19 2016 +0000 +++ b/main.h Thu May 05 14:19:50 2016 +0000 @@ -11,26 +11,59 @@ #include "mbed.h" #include "beep.h" +#include "N5110.h" +#include "SDFileSystem.h" +#include "Joystick.h" +#include "fsmMenu.h" -/** +/** +@namespace lcd +@brief GPIO for LCD screen +*/ +N5110 lcd (PTD3, PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); +/** +@namespace sd +@brief GPIO for SD card holder +*/ +SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); +/** @namespace greenLed @brief GPIO output for green LED +*/ +DigitalOut greenLed(PTC2); +/** @namespace redLed @brief GPIO output for red LED +*/ +DigitalOut redLed(PTA2); +/** @namespace pot @brief GPIO input for the POT +*/ +AnalogIn pot(PTB10); +/** @namespace buzzer @brief GPIO output for buzzer */ +Beep buzzer(PTA1); +/** +@namespace RB +@brief GPIO input for Right Button +*/ +InterruptIn RB(PTE24); +/** +@namespace LB +@brief GPIO input for Left Button +*/ +InterruptIn LB(PTE25); +/** +@namespace gameTicker +@brief ticker to apply logic and update screen +*/ +Ticker gameTicker; -DigitalOut greenLed(PTC2); -DigitalOut redLed(PTA2); -AnalogIn pot(PTB10); -Beep buzzer(PTA1); -InterruptIn RB(PTE24); -InterruptIn LB(PTE25); - -/// create enumerated type (0,1,2,3 etc. for current direction snake is travelling (not joystick reading)) +//Enums +/*! Enum containing current direction of snake */ enum CurrentDirection { up, down, @@ -38,19 +71,23 @@ right, centre, }; -CurrentDirection currentDirection = centre; /// intialise direction at beginning +CurrentDirection currentDirection = centre; //initialise direction -/// create enumerated type (0,1,2 etc. for different game modes on the menu) +/*! Enum containing different game modes */ + enum GameType { classicMode, infiniteMode, hardMode, }; -GameType gameType = classicMode; +GameType gameType = classicMode; //initialise +//Volatile Integers for ISR volatile int game_timer_flag = 0; /*!< flag for game timer isr */ volatile int rb_flag = 0; /*!< flag for right button isr */ volatile int lb_flag = 0; /*!< flag for left button isr */ + +//Integers int randomX = rand() % 83 + 1; /*!< random number in the range of 1 to 83 assigned to randomX */ int randomY = rand() % 47 + 1; /*!< random number in the range of 1 to 47 assigned to randomY */ int randomXoddEven = randomX%2; /*!< distinguish whether randomX is odd or even */ @@ -67,10 +104,23 @@ int prev_j; /*!< integer to store previous value of y/j */ int prev2_i; /*!< integer to store previous, previous value of x/i */ int prev2_j; /*!< integer to store previous, previous value of y/j */ -bool gamePlaying = false; /*!< bool to store whether the game is in play or not */ int pauseCount; /*!< counts how many times the player has paused */ +// Booleans +bool gamePlaying = false; /*!< bool to store whether the game is in play or not */ +// Function proto types +//ISR's +/** @name ISR Functions + * Functions to raise flags + */ +///@{ +void timer_isr(); /*!< Sets the gameTicker flag when called */ +void rb_isr(); /*!< Sets the Right Button flag when called */ +void lb_isr(); /*!< Sets the Left Button flag when called */ +///@} + +//Other functions /** Displays new fruit */