submission

Dependencies:   N5110 mbed

Files at this revision

API Documentation at this revision

Comitter:
el14d2g
Date:
Thu May 05 14:55:20 2016 +0000
Parent:
0:49a79f3e6dff
Commit message:
submission;

Changed in this revision

fsmSnakemain.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/fsmSnakemain.h	Thu May 05 14:46:57 2016 +0000
+++ b/fsmSnakemain.h	Thu May 05 14:55:20 2016 +0000
@@ -15,6 +15,18 @@
 #define DIRECTION_TOLERANCE 0.05f
 
 /**
+@namespace lcd
+@brief lcd object
+*/
+//         VCC,    SCE,   RST,   D/C,   MOSI,  SCLK,   LED
+N5110 lcd(PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); // connections for screen
+
+/**
+@namespace pc (USBTX USBRX);
+@brief serial for devu
+*/
+
+/**
 @namespace button
 @brief Digital in for joystick button
 */
@@ -66,7 +78,7 @@
 
 // set-up the on-board LEDs and switches
 void init_K64F();
-*/
+
 
 
 Ticker pollJoystick, checkJoystick, menuTicker, moveSnake, gameTime;
@@ -249,7 +261,7 @@
 /** snakes head on the y-axis
 */
 
-int sy = 24; set snake at centre
+int sy = 24; //set snake at centre
 
 /** food on the x-axis
 */
@@ -286,3 +298,4 @@
     
 bool gameOver = false;
 
+#endif
\ No newline at end of file
--- a/main.cpp	Thu May 05 14:46:57 2016 +0000
+++ b/main.cpp	Thu May 05 14:55:20 2016 +0000
@@ -1,110 +1,5 @@
 #include "mbed.h"
-#include "N5110.h"
-
-//         VCC,    SCE,   RST,   D/C,   MOSI,  SCLK,   LED
-N5110 lcd(PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); // connections for screen
-
-// change this to alter tolerance of joystick direction
-#define DIRECTION_TOLERANCE 0.05f
-
-
-DigitalIn button(PTB11); // interrupt in for joystick button
-AnalogIn xPot(PTB2); // analog in for joystick x co-ordinate
-AnalogIn yPot(PTB3); // analog in for joystick y co-ordionate
-DigitalOut greenLED (PTD1); // digital out for green LED
-DigitalOut redLED(PTD0); // digital out for red LED
-
-// flag - must be volatile as changes within ISR
-// g_ prefix makes it easier to distinguish it as global
-volatile int g_button_flag = 0;
-volatile int g_timer_flag = 0;
-void menu_isr();
-void button_isr();
-void menu();
-// set-up the on-board LEDs and switches
-void init_K64F();
-
-
-// timer to regularly read the joystick
-Ticker pollJoystick, checkJoystick, menuTicker, moveSnake, gameTime;
-// g_ prefix makes it easier to distinguish it as global
-volatile int g_joystickTimer_flag = 0;
-volatile int g_gameTimer_flag = 0;
-// Serial for debug
-Serial serial(USBTX,USBRX);
-
-// create enumerated type (0,1,2,3 etc. for direction)
-// could be extended for diagonals etc.
-enum DirectionName {
-    UP,
-    DOWN,
-    LEFT,
-    RIGHT,
-    CENTRE,
-    UNKNOWN
-};
-
-enum snakeDirection {
-    up,
-    down,
-    left,
-    right,
-};
-
-// struct for Joystick
-typedef struct JoyStick Joystick;
-struct JoyStick {
-    float x;    // current x value
-    float x0;   // 'centred' x value
-    float y;    // current y value
-    float y0;   // 'centred' y value
-    int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
-    DirectionName direction;  // current direction
-};
-// create struct variable
-Joystick joystick;
-
-int printFlag = 0;
-
-// function prototypes
-void calibrateJoystick();
-void updateJoystick();
-void checkDirection();
-
-// function prototypes
-void gameSetup();
-void nextMoveSnake();
-void printSnake();
-void printFood();
-void generateFood();
-void classic ();
-void snake2();
-void newSnake();
-void timer_isr();
-void update_snake_isr();
-void newDirection();
-void hardWall();
-void wrapAround();
-void snakeTail();
-void game_over();
-void hardwall();
-void gameTimer_ISR();
-void maze ();
-
-
-int i;
-int snakeDirection;
-int width [84]; // set playing area
-int height [48]; // set playing area
-int sx = 48; // set snake at centre
-int sy = 24; // set snake at centre
-int fx; // variable for foods x co'ordinate
-int fy; // variable for foods y co'ordinate
-int score = 0;
-int tailL = 0;
-int tailX [100];
-int tailY [100];
-bool gameOver = false;
+#include "fsmSnakemain.h"
 
 int main()
 {
@@ -214,22 +109,22 @@
 
 void checkDirection()
 {
-        serial.baud(115200);
-        serial.printf("x = %f y = %f button = %d ",joystick.x,joystick.y,joystick.button);
+        pc.baud(115200);
+        pc.printf("x = %f y = %f button = %d ",joystick.x,joystick.y,joystick.button);
 
         // check joystick direction
         if (joystick.direction == UP)
-            serial.printf(" UP\n");
+            pc.printf(" UP\n");
         if (joystick.direction == DOWN)
-            serial.printf(" DOWN\n");
+            pc.printf(" DOWN\n");
         if (joystick.direction == LEFT)
-            serial.printf(" LEFT\n");
+            pc.printf(" LEFT\n");
         if (joystick.direction == RIGHT)
-            serial.printf(" RIGHT\n");
+            pc.printf(" RIGHT\n");
         if (joystick.direction == CENTRE)
-            serial.printf(" CENTRE\n");
+            pc.printf(" CENTRE\n");
         if (joystick.direction == UNKNOWN)
-            serial.printf(" Unsupported direction\n");
+            pc.printf(" Unsupported direction\n");
 
 }