Final Version of: THE ORGINAL ISHTENDO GAMING SYSTEM including modes such as: Snake Etch-a-Sketch Temperature Sensor Also contains a hidden mini game.. Will you be the one to unlock it .... Ihsian Mulla (el14imfm@leeds.ac.uk) 200839613 May 2016

Dependencies:   FXOS8700Q Buzzer ishtendo_vI N5110 SDFileSystem TMP102 mbed

Files at this revision

API Documentation at this revision

Comitter:
Ihsianmulla
Date:
Wed May 04 13:06:09 2016 +0000
Commit message:
Final Version

Changed in this revision

AccelerometerFXOS8700Q.lib Show annotated file Show diff for this revision Revisions of this file
Buzzer.lib Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/DrawFunctions/DrawFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/DrawFunctions/DrawFunctions.h Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/SnakeFunctions/SnakeFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/SnakeFunctions/SnakeFunctions.h Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/TempFunctions/TempFunctions.cpp Show annotated file Show diff for this revision Revisions of this file
GameModeFunctions/TempFunctions/TempFunctions.h Show annotated file Show diff for this revision Revisions of this file
Joystick.lib Show annotated file Show diff for this revision Revisions of this file
N5110.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
TMP102.lib 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
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AccelerometerFXOS8700Q.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Buzzer.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/Ihsianmulla/code/Buzzer/#e29e9889cfb4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/DrawFunctions/DrawFunctions.cpp	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,179 @@
+/** Draw Game Functions
+@brief Used for allowing Etch-a-Sketch Function with user interface
+@file DrawFunctions.cpp
+@author Ihsian Mulla
+@date April 2016
+*/
+
+#include "mbed.h"
+#include "beep.h"
+#include "N5110.h"
+#include "joystick.h"
+#include "FXOS8700Q.h"
+
+#define DIRECTION_TOLERANCE 0.25L
+
+extern N5110 lcd;
+extern Joystick joystick;
+extern Beep buzzer;
+
+// SDA SCL ADDRESS
+FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+FXOS8700Q_mag mag(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
+
+//Serial Pc(USBTX, USBRX);
+
+MotionSensorDataUnits acc_data;
+MotionSensorDataCounts acc_raw;
+
+
+// --------------------GLOBAL VARIABLES ----------------------------------//
+int flag = 0; /*!< sets flag to ensure a one decrement for one press up*/
+/**
+*Limits number of press-up to completion
+@param a - Number of Press-ups
+*/
+int a = 11; /*!< a = Number of Push-Ups to complete game*/
+
+// -- FUNCTION PROTOTYPES -- //
+void Draw();
+void MiniGame();
+void MiniGameIntro();
+void SwitchMenu();
+
+
+void Draw()
+{
+
+    lcd.init(); // initialises the display
+    lcd.clear(); // clears display
+    calibrateJoystick();  // get centred values of joystick
+    //initialise starting pixel position (x,y)
+    int pixel_x, pixel_y;
+    pixel_x = 40;
+    pixel_y = 20;
+
+
+
+    while(1) {
+        lcd.setPixel(pixel_x,pixel_y);// set Pixel (x,y)
+        lcd.refresh();
+        // prevents lines being drawn whilst the button is pressed
+        if(button==1) {
+            lcd.clearPixel(pixel_x,pixel_y);
+        }
+        // allows joystick movement to be reciprocated in drawing direction by adding or subtracting x & y values
+        if (joystick.direction == DOWN) {
+            if (pixel_y <= 0) pixel_y = 0;
+            else pixel_y = pixel_y - 1;
+        }
+        if (joystick.direction == UP) {
+            if (pixel_y >= 48) pixel_y = 48;
+            else pixel_y = pixel_y + 1;
+        }
+        if (joystick.direction == RIGHT) {
+            if (pixel_x <= 0) pixel_x = 0;
+            else pixel_x = pixel_x - 1;
+        }
+        if (joystick.direction == LEFT) {
+            if (pixel_x >= 84) pixel_x = 84;
+            else pixel_x = pixel_x + 1;
+        }
+        if ((pixel_x>74) &&(pixel_y>38)) {
+            MiniGameIntro();
+        }
+        if (Jbutton==1) {
+            SwitchMenu();
+        }
+        wait(0.05);
+    }
+}
+
+
+void MiniGame()
+{
+    lcd.init(); // initialise LCD
+    acc.enable(); // enable the FXOS8700Q accelerometer
+
+    while(1) {
+        lcd.clear(); // clear lcd
+        acc.getAxis(acc_data); // get x,y,z values
+        // Pc.printf("X=%4.1f Y=%4.1f Z=%4.1f\r\n", acc_data.x, acc_data.y, acc_data.z);
+        int Ballx = 44+(-43*acc_data.x); // optimise x values to remain within lcd boundary
+        int Bally = 24+(-23*acc_data.y); // optimise y values to remain within lcd boundary
+        lcd.drawCircle(Ballx,Bally,3,0); // draw ball at cnetre (x,y)
+        // Draws arms on the Push-up man
+        lcd.drawLine(Ballx+1, Bally, 69, 30, 1);
+        lcd.drawLine(Ballx-1, Bally, 20, 30, 1);
+        lcd.drawLine(69, 30, 69, 40, 1);
+        lcd.drawLine(20, 30, 20, 40, 1);
+        lcd.printString("Push",5,1);
+        lcd.printString("Up",10,2);
+
+        if((acc_data.y<0.4)&& (flag==0)) {
+            flag=1; // flag to ensure one push - up = one decrement of 'a'
+            buzzer.beep(1000,0.15); // beep after each push-up
+            a--;
+        }
+        if(acc_data.y>0.5) {
+            flag=0; // reset flag
+        }
+        char pressups [20];
+        sprintf(pressups,"%i",a);
+        lcd.printString(pressups,65,1);
+// When 10 push ups complete (a=0) = completion --> back to menu
+        if(a==0) {
+            while(1) {
+                lcd.clear();
+                lcd.printString("Congrats",10,1);
+                lcd.printString("You Have",10,2);
+                lcd.printString("Completed The",2,3);
+                lcd.printString("Mini Game",10,4);
+                buzzer.beep(1000,0.5);
+                buzzer.beep(1100,0.5);
+                buzzer.beep(1200,0.5);
+                buzzer.beep(1300,0.5);
+                buzzer.beep(1400,0.5);
+                buzzer.beep(1500,0.5);
+                buzzer.beep(1600,0.5);
+                buzzer.beep(1700,0.5);
+                buzzer.beep(1800,0.5);
+                buzzer.beep(1900,0.5);
+                buzzer.beep(2000,0.5);
+                wait(5);
+                SwitchMenu();
+            }
+        }
+        sleep();
+    }
+}
+
+
+void MiniGameIntro()
+{
+    lcd.clear();
+    lcd.printString("You Have",15,1);
+    lcd.printString("Unlocked The",5,2);
+    lcd.printString("Hidden Game",10,3);
+    wait(2);
+    lcd.clear();
+    lcd.printString("The",30,1.5);
+    lcd.printString("Push - Up",15,2.5);
+    lcd.printString("Challenge",15,3.5);
+    wait(2);
+    lcd.clear();
+    lcd.printString("Please Fasten",5,1);
+    lcd.printString("The Game to",5,2);
+    lcd.printString("your arm",15,3);
+    wait(3);
+    lcd.clear();
+    lcd.printString("Press External",1,1);
+    lcd.printString("Button When", 10, 2);
+    lcd.printString("Ready",25,3);
+    while(1) {
+        if (button==1) {
+            MiniGame();
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/DrawFunctions/DrawFunctions.h	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,32 @@
+/**
+@file DrawFunctions.h
+@brief header file for Etch-a-Sketch functions
+*/
+#ifndef DRAWFUNCTIONS_H
+
+#include "mbed.h"
+#include "N5110.h"
+/**
+@author Ihsian Mulla
+@date April 2016
+*/
+
+class DrawFunctions
+{
+public:
+    /** contains the rule set for snake stating global variables and functions for play
+    */
+    void Draw();
+    /**Allows for the pause of the game during snake play
+    */
+    void MiniGame();;
+    /**Allows for the pause of the game during snake play
+    */
+    void MiniGameIntro();
+    /**Allows return to menu from game [prevents having to use NVIC_SystemReset]
+    */
+    void SwitchMenu();
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/SnakeFunctions/SnakeFunctions.cpp	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,286 @@
+/** Snake Game Functions
+*Implementing functions for the control and user interface with the snake
+@file SnakeFunctions.cpp
+@brief contains functions for pause, death and food
+@author Ihsian Mulla
+@date April2016
+*/
+//---Libraries---//
+#include "mbed.h"
+#include "N5110.h"
+#include "beep.h"
+#include "joystick.h"
+#include "SDFileSystem.h"
+#define DIRECTION_TOLERANCE 0.25L
+
+extern Joystick joystick;
+extern N5110 lcd;
+extern Beep buzzer;
+
+// Connections to SD card holder on K64F (SPI interface)
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
+
+Serial serial(USBTX, USBRX);  // for PC debug
+
+
+int Direction = 3; /*!<1-UP 2-DOWN 3-RIGHT 4-LEFT*/
+int Snake_array[150][150]; /*!<Snake postion array*/
+int num = 150; /*!<max snake size*/
+int snake_length =3; /*!<initial snake length*/
+int Highscore[3];/*!<sets initial array of 3 integers*/
+int Score = 0; /*!< initial score*/
+int Fx = 60; /*!< initial food x*/
+int Fy = 20; /*!< intial food y*/
+
+volatile int g_PauseSleep_flag=0; //set flag for timer isr
+
+//---FUNCTIONS--//
+void Snake();
+void Pause();
+void Read();
+void Write();
+void Check();
+void SetFood();
+void ClearFood();
+void PrintCheck();
+void SwitchMenu();
+void PauseSleep_isr();
+
+Ticker PauseSleep;
+
+void Snake()
+{
+    lcd.clear();
+    serial.baud(115200);  // full-speed! set baud rate for SD card
+    lcd.init(); // initialise display
+    int Sx, Sy; //Snake x & Snake y
+    Sx = 43; //Snake initial position x
+    Sy = 23; //snake intial position y
+    SetFood();//Sets food position
+
+    while(1) {
+        //shifts array down for x &y
+        for(int i =num-1; i>0; i--) {
+            Snake_array[0][i]=Snake_array[0][i-1];
+            Snake_array[1][i]=Snake_array[1][i-1];
+        }
+
+        Snake_array[0][0]=Sx;//sets the head of snake as first x value in the array
+        Snake_array[1][0]=Sy;//sets the head of snake as first y value in the array
+        lcd.setPixel(Snake_array[0][1],Snake_array[1][1]);       //set pixels 1st pixel based on x,y value from the array
+        lcd.clearPixel(Snake_array[0][snake_length+1],Snake_array[1][snake_length+1]); //clears pixel behind snake
+        Snake_array[0][snake_length+1]=0;//allows snake to increment in length whilst adding its value to the array to the array
+        Snake_array[0][snake_length+1]=0;
+        lcd.refresh();
+        lcd.setPixel(Sx,Sy); // set snake head position
+        lcd.refresh();
+        wait(0.025);
+// statement to increment score and snake length when the x & y coordinates of the snakes head match those of the food
+        if ((Sx == Fx && Sy==Fy)||(Sx == Fx+1 && Sy==Fy)||(Sx == Fx && Sy==Fy-1)||(Sx == Fx+1 && Sy==Fy-1)) {
+            Score++; // increment score by 1 each time food is consumed
+            ClearFood();
+            buzzer.beep(1000,0.5);//buzzer.beep(frequency.time)
+            Fx = rand() %80; //randomises food position for the x-axis
+            Fy = rand() %44; //randomises food position for the y-axis
+            SetFood();
+            snake_length++; // increment snake length by one pixel
+            lcd.refresh();
+        }
+        // If statement to allow snake direction to maintain previous direction if joystick is at the centre
+        if (joystick.direction == CENTRE) {
+            if (Direction == 1) {
+                Sy++;
+            }
+            if (Direction == 2) {
+                Sy--;
+            }
+            if (Direction == 3) {
+                Sx++;
+            }
+            if (Direction == 4) {
+                Sx--;
+            }
+        }
+        // If statements to control direction of movement with joystick interface
+        if (joystick.direction == UP) {
+            Direction = 1;
+            if (Direction == 1) {
+                Sy++;
+            }
+        }
+        if (joystick.direction == DOWN) {
+            Direction = 2;
+            if (Direction == 2) {
+                Sy--;
+            }
+        }
+        if (joystick.direction == LEFT) {
+            Direction = 3;
+            if (Direction == 3) {
+                Sx++;
+            }
+        }
+        if (joystick.direction == RIGHT) {
+            Direction = 4;
+            if (Direction == 4) {
+                Sx--;
+            }
+        }
+        if (Jbutton==1) {
+            Pause();
+        }
+        //Game Over - if snake head coordinates equal the coordinates of any pixels in the snake array
+        // or the coordinates of the hard boundary or itself
+        for (int i=0; i<=200; i++) {
+            if (((Snake_array[0][i]==Sx)&&(Snake_array[1][i]==Sy))||(Sx>=82)||(Sx <= 0)||(Sy >= 46)||(Sy <= 0)) {
+                buzzer.beep(1500,0.5); //buzzer.beep(frequency(Hz),time(seconds));
+                wait(0.5);
+                buzzer.beep(500,0.5);
+                lcd.clear();
+                lcd.printString("GAME OVER",10,1);
+                lcd.printString("SCORE:",2,3);
+                char buffer[14];
+                sprintf(buffer,"%d",(Score*10));      //serial print score to buffer
+                lcd.printString(buffer,50,3);    //print score to LCD
+                wait(1);
+                Read();
+                Read();
+                Check();
+                Write();
+                Read();
+                lcd.clear();
+                lcd.printString("HighScores",10,0);
+                lcd.drawLine(10,11,68,11,1);
+                lcd.printString("1.",20,2);
+                lcd.printString("2.",20,3);
+                lcd.printString("3.",20,4);
+                char scre[80];
+                for(int i = 0; i < 3; i++) {
+                    sprintf(scre, "%i",Highscore[i]);
+                    lcd.printString(scre,35,i+2);
+                }
+                wait(5);
+                lcd.clear();
+                NVIC_SystemReset();
+            }
+        }
+        wait((0.15-(0.001*Score)));
+    }
+}
+
+
+// ---------------Function to pause/resume the snake game------------------------//
+void Pause()
+{
+    PauseSleep.attach(&PauseSleep_isr,5.0);
+    while(1) {
+        lcd.printString("Pause",25,0.5);
+        lcd.drawLine(25, 9, 53, 9, 1);//underlines pause
+        lcd.printString("Press Button",0,2);
+        lcd.printString("to Continue",15,3);
+        wait(0.1);
+
+        if (button==1) {
+            lcd.clear();
+            SetFood();
+            break;
+        }
+        sleep();
+    }
+}
+//-------------------------------------- Advanced Reading from file -------------------------------//
+void Read()
+{
+    FILE *fp; // this is our file pointer
+    // now open file for reading...note the 'r'
+    fp = fopen("/sd/HScore.txt", "r");
+
+    int n=3;  // going to store the number of lines in the file
+    int *index_array;  // pointers to create dynamic arrays later
+    int *value_array; // note memory will be in heap rather than on the stack
+
+    if (fp == NULL) {  // if it can't open the file then print error message
+        // serial.printf("Error! Unable to open file!\n");
+    } else {
+        //serial.printf("Read %d lines\n",n);
+        // calloc creates an array and initilises to 0
+        // malloc returns unitialised array - diffrent syntax
+        index_array = (int *)calloc(n, sizeof (int));
+        value_array = (int *)calloc(n, sizeof (int));
+
+        int i=0;
+        rewind(fp); // 'scrolled' to end of file, so go back to beginning
+        while (fscanf(fp,"%i,%i",&index_array[i],&value_array[i]) && (i<3)) {
+            i++;  // read data into array and increment index
+        }
+        // we should now have the data in the arrays, will print to serial to check
+        for(int i=0; i<n ; i++) {
+            // serial.printf("[%d] %i,%i\n",i,index_array[i],value_array[i]);
+            Highscore[i]=value_array[i];
+        }
+    }
+    // serial.printf("End\n");
+}
+
+//--------------------- Writing list to file  -----------------------------//
+void Write()
+{
+    FILE *fp; // this is our file pointer
+    fp = fopen("/sd/HScore.txt", "w");
+
+    if (fp == NULL) {  // if it can't open the file then print error message
+        // serial.printf("Error! Unable to open file!\n");
+    } else {  // opened file so can write
+        // serial.printf("Writing to file....");
+        for(int i = 0; i <= 3; i++) {
+            fprintf(fp, "%i,%i \n",i,Highscore[i]);  // print formatted string to file (CSV)
+        }
+        //  serial.printf("Done.\n");
+        fclose(fp);  // ensure you close the file after writing
+    }
+}
+//--------------compares the score to the previous highscores replacing and shifting where necessary---------//
+void Check()
+{
+    if((Score*10)>=Highscore[0]) {
+        Highscore[2]=Highscore[1];
+        Highscore[1]=Highscore[0];
+        Highscore[0]=(Score*10);
+    } else if ((Score)>=Highscore[1]) {
+        Highscore[2]=Highscore[1];
+        Highscore[1]=(Score*10);
+    } else if ((Score)>=Highscore[2]) {
+        Highscore[2]=(Score*10);
+    }
+
+    //PrintCheck();
+
+}
+
+void PrintCheck()
+{
+    serial.printf("%d\n",Highscore[0]);
+    serial.printf("%d\n",Highscore[1]);
+    serial.printf("%d\n",Highscore[2]);
+}
+
+void SetFood()
+{
+    lcd.setPixel(Fx,Fy);
+    lcd.setPixel(Fx+1,Fy);
+    lcd.setPixel(Fx,Fy-1);
+    lcd.setPixel(Fx+1,Fy-1);
+}
+
+void ClearFood()
+{
+    lcd.clearPixel(Fx,Fy);
+    lcd.clearPixel(Fx+1,Fy);
+    lcd.clearPixel(Fx,Fy-1);
+    lcd.clearPixel(Fx+1,Fy-1);
+}
+
+void PauseSleep_isr()
+{
+    g_PauseSleep_flag=1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/SnakeFunctions/SnakeFunctions.h	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,56 @@
+/**
+@file SnakeFunctions.h
+@brief header file for snake functions
+*/
+#ifndef SNAKEFUNCTIONS_H
+
+#include "mbed.h"
+#include "N5110.h"
+
+/**
+@brief This library has been created to allow for snake movement
+@author Ihsian Mulla
+@date April 2016
+*/
+
+
+
+class SnakeFunctions
+{
+public:
+    /** contains the rule set for snake stating global variables and functions for play
+    */
+    void Snake();
+    /**Allows for the pause of the game during snake play
+    */
+    void Pause();
+    /**Function to read array of highscores from sd card
+    */
+    void Read();
+    /**Function to check score against the array of highscores and replace
+    *and shift where necessary
+    */
+    void Check();
+    /**Function to write array to SD card
+    */
+    void Write();
+    /**Set 4 pixels for food
+    */
+    void SetFood();
+    /**Clear 4 pixels for food
+    */
+    void ClearFood();
+    /**Allows the serial print of the Highscore array for testing
+    */
+    void PrintCheck();
+    /**Sets ISR to change flag
+    */
+    void PauseSleep_isr();
+    /**Allows return to menu from game [prevents having to use NVIC_SystemReset
+    */
+    void SwitchMenu();
+
+};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/TempFunctions/TempFunctions.cpp	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,231 @@
+/** Temperature Sensor Functions
+* Used for printing and updating the temperature at 1Hz with unit conversion capabilities
+@file TempFunctions.cpp
+@brief utilises unit conversion formulae within a while loop to allow for unit change.
+@author Ihsian Mulla
+@date April2016
+*/
+
+//---LIBRARIES--//
+#include "mbed.h"
+#include "beep.h"
+#include "TMP102.h"
+#include "N5110.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "joystick.h"
+
+extern Beep buzzer;
+extern N5110 lcd;
+extern Joystick joystick;
+
+// Create TMP102 object
+TMP102 tmp102(I2C_SDA,I2C_SCL);
+
+// K64F on-board LEDs
+DigitalOut re_led(LED_RED);
+DigitalOut g_led(LED_GREEN);
+DigitalOut b_led(LED_BLUE);
+
+//Sets ticker to allow for timer
+Ticker ticker1;
+
+// K64F on-board switches
+InterruptIn sw2(SW2);
+InterruptIn sw3(SW3);
+Serial pc(USBTX,USBRX);
+
+
+int unit_select = 0; /*!< initialising first switch statement */
+int selector =0; /*!< initialising pointer switch statement */
+int next_unit_select = 0; /*!< used to confirm one transition per trigger on the joystick */
+
+volatile int g_timer_flag = 0;
+
+void timer_isr();// ticker function for temperature sensor
+void error(); // error function hangs flashing an LED
+void init_serial(); // setup serial port
+void init_K64F(); // set-up the on-board LEDs and switches
+void Temp(); // temperature code - finite state machine to transition between temperature units.
+void SwitchMenu();//Allows return to menu from game [prevents having to use NVIC_SystemReset]
+
+void Temp()
+{
+    lcd.init(); //  initialise lcd
+    init_K64F();     // initialise the board
+    init_serial(); // initialise the serial port
+    tmp102.init(); //initialise the tmp102 sensor using dot syntax
+    ticker1.attach(&timer_isr,1.0); // sets to read temp sensor at a frequency of 1Hz using a ticker
+    lcd.normalMode();
+    lcd.setBrightness(0.5); // put LED backlight on 50%
+
+
+    while (1) {
+        //change between units of temperature (Kelvin,Celcius,Farenheit)
+        switch(unit_select) {
+                // -- CELCIUS--//
+            case 0:
+                while(1) {
+                    lcd.clear();
+                    lcd.printString("Current",25,0);
+                    lcd.printString("Temperature:",10,1);
+                    lcd.drawCircle(63,30,1,0);
+                    float T = tmp102.get_temperature();
+                    char Temp1 [20];
+                    sprintf(Temp1,"T = %2.2f  C",T);
+                    lcd.printString (Temp1,2,4);
+                    wait(0.1);
+                    lcd.refresh();
+                    if(joystick.direction==UP) {
+                        selector=1;
+                        break;
+                    } else if(joystick.direction==DOWN) {
+                        selector=2;
+                        break;
+                    } else {
+                        selector=0;
+                        break;
+                    }
+                }
+//makes use of a switch statement within a switch statement to allow for joystick input to state transition
+                switch(selector) {
+                    case 0:
+                        unit_select=3;
+                        next_unit_select=0;
+                        break;
+                    case 1:
+                        unit_select=3;
+                        next_unit_select=2;
+                        break;
+                    case 2:
+                        unit_select=3;
+                        next_unit_select=1;
+                        break;
+                }
+                break;
+                //----Farenheit---//
+            case 1:
+                while(1) {
+                    lcd.clear();
+                    lcd.printString("Current",25,0);
+                    lcd.printString("Temperature:",10,1);
+                    lcd.drawCircle(63,30,1,0);
+                    float T = tmp102.get_temperature();
+                    char Temp2 [20];
+                    sprintf(Temp2,"T = %2.2f  F",((T*1.8)+32));
+                    lcd.printString (Temp2,2,4);
+                    wait(0.1);
+                    lcd.refresh();
+                    if(joystick.direction==UP) {
+                        selector=1;
+                        break;
+                    } else if(joystick.direction==DOWN) {
+                        selector=2;
+                        break;
+                    } else {
+                        selector=0;
+                        break;
+                    }
+                }
+                switch(selector) {
+                    case 0:
+                        unit_select=3;
+                        next_unit_select=1;
+                        break;
+                    case 1:
+                        unit_select=3;
+                        next_unit_select=0;
+                        break;
+                    case 2:
+                        unit_select=3;
+                        next_unit_select=2;
+                        break;
+                }
+                break;
+                //-----KELVIN----//
+            case 2:
+                while(1) {
+                    lcd.clear();
+                    lcd.printString("Current",25,0);
+                    lcd.printString("Temperature:",10,1);
+                    float T = tmp102.get_temperature();
+                    char Temp3 [20];
+                    sprintf(Temp3,"T = %3.2f K",T+273.15);
+                    lcd.printString (Temp3,2,4);
+                    wait(0.1);
+                    lcd.refresh();
+                    if(joystick.direction==UP) {
+                        selector=1;
+                        break;
+                    } else if(joystick.direction==DOWN) {
+                        selector=2;
+                        break;
+                    } else {
+                        selector=0;
+                        break;
+                    }
+                }
+                switch(selector) {
+                    case 0:
+                        unit_select=3;
+                        next_unit_select=2;
+                        break;
+                    case 1:
+                        unit_select=3;
+                        next_unit_select=1;
+                        break;
+                    case 2:
+                        unit_select=3;
+                        next_unit_select=0;
+                        break;
+                }
+                break;
+                // Case to check that there is only a single transition between states per trigger of the joystick
+            case 3:
+                if(joystick.direction==CENTRE) {
+                    unit_select=next_unit_select;
+                } else {
+                    unit_select=3;
+                }
+                break;
+            default:
+                error();  //invalid state - call error routine
+                break;
+        }
+        //wait(0.05);
+        sleep();
+        if (Jbutton==1) {
+            SwitchMenu();
+        }
+    }
+}
+
+
+
+void timer_isr()
+{
+    g_timer_flag = 1;   // set flag in ISR
+}
+
+void init_K64F()
+{
+    // on-board LEDs are active-low, so set pin high to turn them off.
+    re_led = 1;
+    g_led = 1;
+    b_led = 1;
+
+    // since the on-board switches have external pull-ups, we should disable the internal pull-down
+    // resistors that are enabled by default using InterruptIn
+    sw2.mode(PullNone);
+    sw3.mode(PullNone);
+
+}
+
+
+void init_serial()
+{
+    // set to highest baud - ensure terminal software matches
+    pc.baud(115200);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GameModeFunctions/TempFunctions/TempFunctions.h	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,34 @@
+/**
+@file TempFunctions.h
+@brief header file for temperature functions
+*/
+#ifndef TEMPFUNCTIONS_H
+
+#include "mbed.h"
+#include "N5110.h"
+/**
+@author Ihsian Mulla
+@date April 2016
+*/
+
+class TempFunctions
+{
+public:
+    /** contains the rule set for snake stating global variables and functions for play
+    */
+    void timer_isr();
+    /**Allows for the pause of the game during snake play
+    */
+    void error();
+    /**Allows for the pause of the game during snake play
+    */
+    void init_serial();
+    /**Allows for the pause of the game during snake play
+    */
+    void init_K64F();
+    /**Allows for the pause of the game during snake play
+    */
+    void Temp();
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Joystick.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ELEC2645-201516/code/ishtendo_vI/#f79fe9dc65ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/eencae/code/N5110/#ba8addc061ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP102.lib	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ELEC2645-201516/code/TMP102/#aae68f8782a6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,235 @@
+//---------------------------- IHSIAN MULLA  -------------------------------------------//
+//---------------------------- PRESENTS..... ------------------------------------------//
+// ------------ THE ISHTENDO ORIGINAL GAMING SYSTEM ----------------------------------//
+
+
+//----------------LIBRARIES-----------//////
+#include "N5110.h"
+#include "joystick.h"
+#include "mbed.h"
+#include "TMP102.h"
+#include "beep.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+// Buzzer connceted to PWM pin
+Beep buzzer(PTC10);
+
+//On-board RGB led (only need one)
+DigitalOut r_led(LED_RED);
+
+// connections for joystick
+AnalogIn xPot(PTB3);
+AnalogIn yPot(PTB2);
+DigitalIn Jbutton(PTB11);
+InterruptIn button(PTB18);// Connection for external button
+
+//         VCC,    SCE,   RST,   D/C,   MOSI,  SCLK,   LED
+N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
+
+// Ticker functions for joystick and menu
+Ticker MenuRefresh;
+Ticker pollJoystick;
+
+Joystick joystick;
+
+// ---- Global Variables---//
+int nextmenu=0; /*!< initialises chekc statement for single transition */
+int menu = 0; /*!< initialises menu switch statement */
+int pointer = 0; /*!< initialises pointer switch statement */
+
+volatile int g_button_flag = 0; // sets flag in the ISR
+volatile int g_MenuRefresh_flag=0; // sets the flag in the ISR
+
+//--Functions--//
+void error();
+void Snake();
+void Draw();
+void Temp();
+void Intro();
+void MenuOptions();
+void SwitchMenu();
+void MenuRefresh_isr();
+void button_isr();
+
+
+//--------------------  MAIN  ------------------------------------------//
+
+int main()
+{
+    lcd.init(); // intialise LCD
+    lcd.setBrightness(0.5);
+    lcd.normalMode();
+    Intro();
+    calibrateJoystick();  // get centred values of joystick
+    pollJoystick.attach(&updateJoystick,0.25);  // read joystick 10 times per second
+    SwitchMenu();
+}
+
+void Intro()
+{
+    lcd.printString("ishtendo",10,2);
+    lcd.printString("vI",70,5);
+    lcd.printString(".",45,3);
+    buzzer.beep(1000,0.5);
+    wait(1.0);
+    lcd.printString(".",55,3);
+    buzzer.beep(1000,0.5);
+    wait(1.0);
+    lcd.printString(".",65,3);
+    buzzer.beep(1000,0.5);
+    wait(1.0);
+    buzzer.beep(1500,0.5);
+    lcd.clear();
+    lcd.refresh();
+}
+
+void MenuOptions()
+{
+    lcd.printString("Snake",30,0.5);
+    lcd.printString("Draw",33,2.5);
+    lcd.printString("Temp Sensor",5,4.5);
+}
+
+//switch statement to allow for selection and option highlight user interface
+void SwitchMenu()
+{
+    button.fall(&button_isr);
+    button.mode(PullDown);
+    MenuRefresh.attach(&MenuRefresh_isr,0.5); //attach ticker to prevent the board sleeping and becoming unresponsive
+
+    while(1) {
+        switch (menu) {
+            case 0: // Snake Selection
+                lcd.clear();
+                MenuOptions();
+                lcd.printString("<",75,0.5);//
+                // check if flag i.e. interrupt has occured
+                if (g_button_flag) {
+                    g_button_flag = 0;  // if it has, clear the flag
+                    Snake();
+                }
+                if(joystick.direction==DOWN)
+                    pointer=1;
+                else if(joystick.direction==UP)
+                    pointer=2;
+                else
+                    pointer=0;
+                //implements a switch statement within a switch statement to allow user interface from a joystick
+                //to transition between the 3 states to highlight and select a game option
+                switch(pointer) {
+                    case 0:
+                        menu=3;
+                        nextmenu=0;
+                        break;
+                    case 1:
+                        menu=3;
+                        nextmenu=2;
+                        break;
+                    case 2:
+                        menu=3;
+                        nextmenu=1;
+                        break;
+                }
+                break;
+            case 1 : // Draw Selection
+                lcd.clear();
+                MenuOptions();
+                lcd.printString("<",75,2.5);
+                // check if flag i.e. interrupt has occured
+                if (g_button_flag) {
+                    g_button_flag = 0;  // if it has, clear the flag
+                    Draw();
+                }
+                if(joystick.direction==DOWN)
+                    pointer=1;
+                else if(joystick.direction==UP)
+                    pointer=2;
+                else
+                    pointer=0;
+                switch(pointer) {
+                    case 0:
+                        menu=3;
+                        nextmenu=1;
+                        break;
+                    case 1:
+                        menu=3;
+                        nextmenu=0;
+                        break;
+                    case 2:
+                        menu=3;
+                        nextmenu=2;
+                        break;
+                }
+                break;
+            case 2 : //Temperature Sensor Selection
+                lcd.clear();
+                MenuOptions();
+                lcd.printString("<",75,4.5);
+                // check if flag i.e. interrupt has occured
+                if (g_button_flag) {
+                    g_button_flag = 0;  // if it has, clear the flag
+                    Temp();
+                }
+                if(joystick.direction==DOWN) {
+                    pointer=1;
+
+                } else if (joystick.direction==UP) {
+                    pointer=2;
+
+                } else {
+                    pointer=0;
+                }
+                switch(pointer) {
+                    case 0:
+                        menu=3;
+                        nextmenu=2;
+                        break;
+                    case 1:
+                        menu=3;
+                        nextmenu=1;
+                        break;
+                    case 2:
+                        menu=3;
+                        nextmenu=0;
+                        break;
+                }
+                break;
+            case 3: //Checks to prevent multiple transitions of menu cursor (one transition per joystick movement)
+                if(joystick.direction==CENTRE) {
+                    menu=nextmenu;
+                } else {
+                    menu=3;
+                }
+                break;
+            default:
+                error();  //invalid state - call error routine
+                // or could jump to starting state i.e. state = 0
+                break;
+        }
+        sleep();
+    }
+}
+
+//  event-triggered interrupt
+void button_isr()
+{
+    g_button_flag = 1;   // set flag in ISR
+
+}
+//Timer isr
+void MenuRefresh_isr()
+{
+    g_MenuRefresh_flag =1;
+}
+
+//  error message -  flashing red led
+void error()
+{
+    while(1) {
+        r_led = 0;
+        wait(0.2);
+        r_led = 1;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,55 @@
+/** Menu Functions
+@file main.h
+@brief Contains global variables, function prototypes and menu code
+*/
+#ifndef _MAIN_H_
+
+#define _MAIN_H_
+
+#include "N5110.h"
+#include "joystick.h"
+#include "mbed.h"
+#include "TMP102.h"
+#include "beep.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+/**
+@brief what it does
+@author Ihsian Mulla
+@date April 2016
+*/
+
+
+class MainFunctions
+{
+public:
+    /** Contains the code for the introduction to the game
+    */
+    void Intro();
+    /** Allows return to menu from game [prevents having to use NVIC_SystemReset
+    */
+    void SwitchMenu();
+    /** writes the options as strings to the Nokia LCD screen
+    */
+    void MenuOptions();
+    /**  functions to allow user interface to play snake
+    */
+    void Snake();
+    /** functions to allow user interface to use etch-a-sketch (contains hidden mini game)
+    */
+    void Draw();
+    /** Contains functions for the temperature snsor with variable unit conversion
+    */
+    void Temp();
+    /**Clear 4 pixels for food
+    */
+    void button_isr();
+    /**Allows the serial print of the Highscore array for testing
+    */
+    void error();
+
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 04 13:06:09 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f
\ No newline at end of file