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

Committer:
Ihsianmulla
Date:
Wed May 04 13:06:09 2016 +0000
Revision:
0:0fbe9794df10
Final Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ihsianmulla 0:0fbe9794df10 1 //---------------------------- IHSIAN MULLA -------------------------------------------//
Ihsianmulla 0:0fbe9794df10 2 //---------------------------- PRESENTS..... ------------------------------------------//
Ihsianmulla 0:0fbe9794df10 3 // ------------ THE ISHTENDO ORIGINAL GAMING SYSTEM ----------------------------------//
Ihsianmulla 0:0fbe9794df10 4
Ihsianmulla 0:0fbe9794df10 5
Ihsianmulla 0:0fbe9794df10 6 //----------------LIBRARIES-----------//////
Ihsianmulla 0:0fbe9794df10 7 #include "N5110.h"
Ihsianmulla 0:0fbe9794df10 8 #include "joystick.h"
Ihsianmulla 0:0fbe9794df10 9 #include "mbed.h"
Ihsianmulla 0:0fbe9794df10 10 #include "TMP102.h"
Ihsianmulla 0:0fbe9794df10 11 #include "beep.h"
Ihsianmulla 0:0fbe9794df10 12 #include <stdio.h>
Ihsianmulla 0:0fbe9794df10 13 #include <stdlib.h>
Ihsianmulla 0:0fbe9794df10 14
Ihsianmulla 0:0fbe9794df10 15 // Buzzer connceted to PWM pin
Ihsianmulla 0:0fbe9794df10 16 Beep buzzer(PTC10);
Ihsianmulla 0:0fbe9794df10 17
Ihsianmulla 0:0fbe9794df10 18 //On-board RGB led (only need one)
Ihsianmulla 0:0fbe9794df10 19 DigitalOut r_led(LED_RED);
Ihsianmulla 0:0fbe9794df10 20
Ihsianmulla 0:0fbe9794df10 21 // connections for joystick
Ihsianmulla 0:0fbe9794df10 22 AnalogIn xPot(PTB3);
Ihsianmulla 0:0fbe9794df10 23 AnalogIn yPot(PTB2);
Ihsianmulla 0:0fbe9794df10 24 DigitalIn Jbutton(PTB11);
Ihsianmulla 0:0fbe9794df10 25 InterruptIn button(PTB18);// Connection for external button
Ihsianmulla 0:0fbe9794df10 26
Ihsianmulla 0:0fbe9794df10 27 // VCC, SCE, RST, D/C, MOSI, SCLK, LED
Ihsianmulla 0:0fbe9794df10 28 N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
Ihsianmulla 0:0fbe9794df10 29
Ihsianmulla 0:0fbe9794df10 30 // Ticker functions for joystick and menu
Ihsianmulla 0:0fbe9794df10 31 Ticker MenuRefresh;
Ihsianmulla 0:0fbe9794df10 32 Ticker pollJoystick;
Ihsianmulla 0:0fbe9794df10 33
Ihsianmulla 0:0fbe9794df10 34 Joystick joystick;
Ihsianmulla 0:0fbe9794df10 35
Ihsianmulla 0:0fbe9794df10 36 // ---- Global Variables---//
Ihsianmulla 0:0fbe9794df10 37 int nextmenu=0; /*!< initialises chekc statement for single transition */
Ihsianmulla 0:0fbe9794df10 38 int menu = 0; /*!< initialises menu switch statement */
Ihsianmulla 0:0fbe9794df10 39 int pointer = 0; /*!< initialises pointer switch statement */
Ihsianmulla 0:0fbe9794df10 40
Ihsianmulla 0:0fbe9794df10 41 volatile int g_button_flag = 0; // sets flag in the ISR
Ihsianmulla 0:0fbe9794df10 42 volatile int g_MenuRefresh_flag=0; // sets the flag in the ISR
Ihsianmulla 0:0fbe9794df10 43
Ihsianmulla 0:0fbe9794df10 44 //--Functions--//
Ihsianmulla 0:0fbe9794df10 45 void error();
Ihsianmulla 0:0fbe9794df10 46 void Snake();
Ihsianmulla 0:0fbe9794df10 47 void Draw();
Ihsianmulla 0:0fbe9794df10 48 void Temp();
Ihsianmulla 0:0fbe9794df10 49 void Intro();
Ihsianmulla 0:0fbe9794df10 50 void MenuOptions();
Ihsianmulla 0:0fbe9794df10 51 void SwitchMenu();
Ihsianmulla 0:0fbe9794df10 52 void MenuRefresh_isr();
Ihsianmulla 0:0fbe9794df10 53 void button_isr();
Ihsianmulla 0:0fbe9794df10 54
Ihsianmulla 0:0fbe9794df10 55
Ihsianmulla 0:0fbe9794df10 56 //-------------------- MAIN ------------------------------------------//
Ihsianmulla 0:0fbe9794df10 57
Ihsianmulla 0:0fbe9794df10 58 int main()
Ihsianmulla 0:0fbe9794df10 59 {
Ihsianmulla 0:0fbe9794df10 60 lcd.init(); // intialise LCD
Ihsianmulla 0:0fbe9794df10 61 lcd.setBrightness(0.5);
Ihsianmulla 0:0fbe9794df10 62 lcd.normalMode();
Ihsianmulla 0:0fbe9794df10 63 Intro();
Ihsianmulla 0:0fbe9794df10 64 calibrateJoystick(); // get centred values of joystick
Ihsianmulla 0:0fbe9794df10 65 pollJoystick.attach(&updateJoystick,0.25); // read joystick 10 times per second
Ihsianmulla 0:0fbe9794df10 66 SwitchMenu();
Ihsianmulla 0:0fbe9794df10 67 }
Ihsianmulla 0:0fbe9794df10 68
Ihsianmulla 0:0fbe9794df10 69 void Intro()
Ihsianmulla 0:0fbe9794df10 70 {
Ihsianmulla 0:0fbe9794df10 71 lcd.printString("ishtendo",10,2);
Ihsianmulla 0:0fbe9794df10 72 lcd.printString("vI",70,5);
Ihsianmulla 0:0fbe9794df10 73 lcd.printString(".",45,3);
Ihsianmulla 0:0fbe9794df10 74 buzzer.beep(1000,0.5);
Ihsianmulla 0:0fbe9794df10 75 wait(1.0);
Ihsianmulla 0:0fbe9794df10 76 lcd.printString(".",55,3);
Ihsianmulla 0:0fbe9794df10 77 buzzer.beep(1000,0.5);
Ihsianmulla 0:0fbe9794df10 78 wait(1.0);
Ihsianmulla 0:0fbe9794df10 79 lcd.printString(".",65,3);
Ihsianmulla 0:0fbe9794df10 80 buzzer.beep(1000,0.5);
Ihsianmulla 0:0fbe9794df10 81 wait(1.0);
Ihsianmulla 0:0fbe9794df10 82 buzzer.beep(1500,0.5);
Ihsianmulla 0:0fbe9794df10 83 lcd.clear();
Ihsianmulla 0:0fbe9794df10 84 lcd.refresh();
Ihsianmulla 0:0fbe9794df10 85 }
Ihsianmulla 0:0fbe9794df10 86
Ihsianmulla 0:0fbe9794df10 87 void MenuOptions()
Ihsianmulla 0:0fbe9794df10 88 {
Ihsianmulla 0:0fbe9794df10 89 lcd.printString("Snake",30,0.5);
Ihsianmulla 0:0fbe9794df10 90 lcd.printString("Draw",33,2.5);
Ihsianmulla 0:0fbe9794df10 91 lcd.printString("Temp Sensor",5,4.5);
Ihsianmulla 0:0fbe9794df10 92 }
Ihsianmulla 0:0fbe9794df10 93
Ihsianmulla 0:0fbe9794df10 94 //switch statement to allow for selection and option highlight user interface
Ihsianmulla 0:0fbe9794df10 95 void SwitchMenu()
Ihsianmulla 0:0fbe9794df10 96 {
Ihsianmulla 0:0fbe9794df10 97 button.fall(&button_isr);
Ihsianmulla 0:0fbe9794df10 98 button.mode(PullDown);
Ihsianmulla 0:0fbe9794df10 99 MenuRefresh.attach(&MenuRefresh_isr,0.5); //attach ticker to prevent the board sleeping and becoming unresponsive
Ihsianmulla 0:0fbe9794df10 100
Ihsianmulla 0:0fbe9794df10 101 while(1) {
Ihsianmulla 0:0fbe9794df10 102 switch (menu) {
Ihsianmulla 0:0fbe9794df10 103 case 0: // Snake Selection
Ihsianmulla 0:0fbe9794df10 104 lcd.clear();
Ihsianmulla 0:0fbe9794df10 105 MenuOptions();
Ihsianmulla 0:0fbe9794df10 106 lcd.printString("<",75,0.5);//
Ihsianmulla 0:0fbe9794df10 107 // check if flag i.e. interrupt has occured
Ihsianmulla 0:0fbe9794df10 108 if (g_button_flag) {
Ihsianmulla 0:0fbe9794df10 109 g_button_flag = 0; // if it has, clear the flag
Ihsianmulla 0:0fbe9794df10 110 Snake();
Ihsianmulla 0:0fbe9794df10 111 }
Ihsianmulla 0:0fbe9794df10 112 if(joystick.direction==DOWN)
Ihsianmulla 0:0fbe9794df10 113 pointer=1;
Ihsianmulla 0:0fbe9794df10 114 else if(joystick.direction==UP)
Ihsianmulla 0:0fbe9794df10 115 pointer=2;
Ihsianmulla 0:0fbe9794df10 116 else
Ihsianmulla 0:0fbe9794df10 117 pointer=0;
Ihsianmulla 0:0fbe9794df10 118 //implements a switch statement within a switch statement to allow user interface from a joystick
Ihsianmulla 0:0fbe9794df10 119 //to transition between the 3 states to highlight and select a game option
Ihsianmulla 0:0fbe9794df10 120 switch(pointer) {
Ihsianmulla 0:0fbe9794df10 121 case 0:
Ihsianmulla 0:0fbe9794df10 122 menu=3;
Ihsianmulla 0:0fbe9794df10 123 nextmenu=0;
Ihsianmulla 0:0fbe9794df10 124 break;
Ihsianmulla 0:0fbe9794df10 125 case 1:
Ihsianmulla 0:0fbe9794df10 126 menu=3;
Ihsianmulla 0:0fbe9794df10 127 nextmenu=2;
Ihsianmulla 0:0fbe9794df10 128 break;
Ihsianmulla 0:0fbe9794df10 129 case 2:
Ihsianmulla 0:0fbe9794df10 130 menu=3;
Ihsianmulla 0:0fbe9794df10 131 nextmenu=1;
Ihsianmulla 0:0fbe9794df10 132 break;
Ihsianmulla 0:0fbe9794df10 133 }
Ihsianmulla 0:0fbe9794df10 134 break;
Ihsianmulla 0:0fbe9794df10 135 case 1 : // Draw Selection
Ihsianmulla 0:0fbe9794df10 136 lcd.clear();
Ihsianmulla 0:0fbe9794df10 137 MenuOptions();
Ihsianmulla 0:0fbe9794df10 138 lcd.printString("<",75,2.5);
Ihsianmulla 0:0fbe9794df10 139 // check if flag i.e. interrupt has occured
Ihsianmulla 0:0fbe9794df10 140 if (g_button_flag) {
Ihsianmulla 0:0fbe9794df10 141 g_button_flag = 0; // if it has, clear the flag
Ihsianmulla 0:0fbe9794df10 142 Draw();
Ihsianmulla 0:0fbe9794df10 143 }
Ihsianmulla 0:0fbe9794df10 144 if(joystick.direction==DOWN)
Ihsianmulla 0:0fbe9794df10 145 pointer=1;
Ihsianmulla 0:0fbe9794df10 146 else if(joystick.direction==UP)
Ihsianmulla 0:0fbe9794df10 147 pointer=2;
Ihsianmulla 0:0fbe9794df10 148 else
Ihsianmulla 0:0fbe9794df10 149 pointer=0;
Ihsianmulla 0:0fbe9794df10 150 switch(pointer) {
Ihsianmulla 0:0fbe9794df10 151 case 0:
Ihsianmulla 0:0fbe9794df10 152 menu=3;
Ihsianmulla 0:0fbe9794df10 153 nextmenu=1;
Ihsianmulla 0:0fbe9794df10 154 break;
Ihsianmulla 0:0fbe9794df10 155 case 1:
Ihsianmulla 0:0fbe9794df10 156 menu=3;
Ihsianmulla 0:0fbe9794df10 157 nextmenu=0;
Ihsianmulla 0:0fbe9794df10 158 break;
Ihsianmulla 0:0fbe9794df10 159 case 2:
Ihsianmulla 0:0fbe9794df10 160 menu=3;
Ihsianmulla 0:0fbe9794df10 161 nextmenu=2;
Ihsianmulla 0:0fbe9794df10 162 break;
Ihsianmulla 0:0fbe9794df10 163 }
Ihsianmulla 0:0fbe9794df10 164 break;
Ihsianmulla 0:0fbe9794df10 165 case 2 : //Temperature Sensor Selection
Ihsianmulla 0:0fbe9794df10 166 lcd.clear();
Ihsianmulla 0:0fbe9794df10 167 MenuOptions();
Ihsianmulla 0:0fbe9794df10 168 lcd.printString("<",75,4.5);
Ihsianmulla 0:0fbe9794df10 169 // check if flag i.e. interrupt has occured
Ihsianmulla 0:0fbe9794df10 170 if (g_button_flag) {
Ihsianmulla 0:0fbe9794df10 171 g_button_flag = 0; // if it has, clear the flag
Ihsianmulla 0:0fbe9794df10 172 Temp();
Ihsianmulla 0:0fbe9794df10 173 }
Ihsianmulla 0:0fbe9794df10 174 if(joystick.direction==DOWN) {
Ihsianmulla 0:0fbe9794df10 175 pointer=1;
Ihsianmulla 0:0fbe9794df10 176
Ihsianmulla 0:0fbe9794df10 177 } else if (joystick.direction==UP) {
Ihsianmulla 0:0fbe9794df10 178 pointer=2;
Ihsianmulla 0:0fbe9794df10 179
Ihsianmulla 0:0fbe9794df10 180 } else {
Ihsianmulla 0:0fbe9794df10 181 pointer=0;
Ihsianmulla 0:0fbe9794df10 182 }
Ihsianmulla 0:0fbe9794df10 183 switch(pointer) {
Ihsianmulla 0:0fbe9794df10 184 case 0:
Ihsianmulla 0:0fbe9794df10 185 menu=3;
Ihsianmulla 0:0fbe9794df10 186 nextmenu=2;
Ihsianmulla 0:0fbe9794df10 187 break;
Ihsianmulla 0:0fbe9794df10 188 case 1:
Ihsianmulla 0:0fbe9794df10 189 menu=3;
Ihsianmulla 0:0fbe9794df10 190 nextmenu=1;
Ihsianmulla 0:0fbe9794df10 191 break;
Ihsianmulla 0:0fbe9794df10 192 case 2:
Ihsianmulla 0:0fbe9794df10 193 menu=3;
Ihsianmulla 0:0fbe9794df10 194 nextmenu=0;
Ihsianmulla 0:0fbe9794df10 195 break;
Ihsianmulla 0:0fbe9794df10 196 }
Ihsianmulla 0:0fbe9794df10 197 break;
Ihsianmulla 0:0fbe9794df10 198 case 3: //Checks to prevent multiple transitions of menu cursor (one transition per joystick movement)
Ihsianmulla 0:0fbe9794df10 199 if(joystick.direction==CENTRE) {
Ihsianmulla 0:0fbe9794df10 200 menu=nextmenu;
Ihsianmulla 0:0fbe9794df10 201 } else {
Ihsianmulla 0:0fbe9794df10 202 menu=3;
Ihsianmulla 0:0fbe9794df10 203 }
Ihsianmulla 0:0fbe9794df10 204 break;
Ihsianmulla 0:0fbe9794df10 205 default:
Ihsianmulla 0:0fbe9794df10 206 error(); //invalid state - call error routine
Ihsianmulla 0:0fbe9794df10 207 // or could jump to starting state i.e. state = 0
Ihsianmulla 0:0fbe9794df10 208 break;
Ihsianmulla 0:0fbe9794df10 209 }
Ihsianmulla 0:0fbe9794df10 210 sleep();
Ihsianmulla 0:0fbe9794df10 211 }
Ihsianmulla 0:0fbe9794df10 212 }
Ihsianmulla 0:0fbe9794df10 213
Ihsianmulla 0:0fbe9794df10 214 // event-triggered interrupt
Ihsianmulla 0:0fbe9794df10 215 void button_isr()
Ihsianmulla 0:0fbe9794df10 216 {
Ihsianmulla 0:0fbe9794df10 217 g_button_flag = 1; // set flag in ISR
Ihsianmulla 0:0fbe9794df10 218
Ihsianmulla 0:0fbe9794df10 219 }
Ihsianmulla 0:0fbe9794df10 220 //Timer isr
Ihsianmulla 0:0fbe9794df10 221 void MenuRefresh_isr()
Ihsianmulla 0:0fbe9794df10 222 {
Ihsianmulla 0:0fbe9794df10 223 g_MenuRefresh_flag =1;
Ihsianmulla 0:0fbe9794df10 224 }
Ihsianmulla 0:0fbe9794df10 225
Ihsianmulla 0:0fbe9794df10 226 // error message - flashing red led
Ihsianmulla 0:0fbe9794df10 227 void error()
Ihsianmulla 0:0fbe9794df10 228 {
Ihsianmulla 0:0fbe9794df10 229 while(1) {
Ihsianmulla 0:0fbe9794df10 230 r_led = 0;
Ihsianmulla 0:0fbe9794df10 231 wait(0.2);
Ihsianmulla 0:0fbe9794df10 232 r_led = 1;
Ihsianmulla 0:0fbe9794df10 233 wait(0.2);
Ihsianmulla 0:0fbe9794df10 234 }
Ihsianmulla 0:0fbe9794df10 235 }