Displayansteuerung mit einzelansteuerung der Module mit 1, 2, 3, 4

Dependencies:   mbed

Committer:
burked01
Date:
Tue Dec 12 12:33:43 2017 +0000
Revision:
0:5dc28ed27b01

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
burked01 0:5dc28ed27b01 1 #include "mbed.h"
burked01 0:5dc28ed27b01 2 #include <string>
burked01 0:5dc28ed27b01 3 #include <stdio.h> /* printf, scanf, puts, NULL */
burked01 0:5dc28ed27b01 4 #include <stdlib.h> /* srand, rand */
burked01 0:5dc28ed27b01 5 #include <time.h> /* time */
burked01 0:5dc28ed27b01 6 using std::string;
burked01 0:5dc28ed27b01 7 // p5: DIN, p7: CLK, p8: LOAD/CS
burked01 0:5dc28ed27b01 8 SPI max72_spi(PA_7, PA_6, PA_5);
burked01 0:5dc28ed27b01 9 DigitalOut load(D2);
burked01 0:5dc28ed27b01 10 Serial pc(SERIAL_TX, SERIAL_RX);
burked01 0:5dc28ed27b01 11 InterruptIn mybutton(USER_BUTTON);
burked01 0:5dc28ed27b01 12 int maxInUse = 4; //Anzahl der Benutzen MAX7219
burked01 0:5dc28ed27b01 13
burked01 0:5dc28ed27b01 14 // define max7219 registers
burked01 0:5dc28ed27b01 15 #define max7219_reg_noop 0x00
burked01 0:5dc28ed27b01 16 #define max7219_reg_digit0 0x01
burked01 0:5dc28ed27b01 17 #define max7219_reg_digit1 0x02
burked01 0:5dc28ed27b01 18 #define max7219_reg_digit2 0x03
burked01 0:5dc28ed27b01 19 #define max7219_reg_digit3 0x04
burked01 0:5dc28ed27b01 20 #define max7219_reg_digit4 0x05
burked01 0:5dc28ed27b01 21 #define max7219_reg_digit5 0x06
burked01 0:5dc28ed27b01 22 #define max7219_reg_digit6 0x07
burked01 0:5dc28ed27b01 23 #define max7219_reg_digit7 0x08
burked01 0:5dc28ed27b01 24 #define max7219_reg_decodeMode 0x09
burked01 0:5dc28ed27b01 25 #define max7219_reg_intensity 0x0a
burked01 0:5dc28ed27b01 26 #define max7219_reg_scanLimit 0x0b
burked01 0:5dc28ed27b01 27 #define max7219_reg_shutdown 0x0c
burked01 0:5dc28ed27b01 28 #define max7219_reg_displayTest 0x0f
burked01 0:5dc28ed27b01 29
burked01 0:5dc28ed27b01 30 #define LOW 0
burked01 0:5dc28ed27b01 31 #define HIGH 1
burked01 0:5dc28ed27b01 32 #define MHZ 1000000
burked01 0:5dc28ed27b01 33
burked01 0:5dc28ed27b01 34 void maxSingle( int reg, int col) {
burked01 0:5dc28ed27b01 35 //maxSingle is the "easy" function to use for a
burked01 0:5dc28ed27b01 36 //single max7219
burked01 0:5dc28ed27b01 37 load = LOW; // begin
burked01 0:5dc28ed27b01 38 max72_spi.write(reg); // specify register
burked01 0:5dc28ed27b01 39 max72_spi.write(col); // put data
burked01 0:5dc28ed27b01 40 load = HIGH; // make sure data is loaded (on rising edge of LOAD/CS)
burked01 0:5dc28ed27b01 41 }
burked01 0:5dc28ed27b01 42
burked01 0:5dc28ed27b01 43 void maxAll (int reg, int col) { // initialize all MAX7219's in the system
burked01 0:5dc28ed27b01 44 load = LOW; // begin
burked01 0:5dc28ed27b01 45 for ( int c=1; c<= maxInUse; c++) {
burked01 0:5dc28ed27b01 46 max72_spi.write(reg); // specify register
burked01 0:5dc28ed27b01 47 max72_spi.write(col); // put data
burked01 0:5dc28ed27b01 48 }
burked01 0:5dc28ed27b01 49 load = HIGH;
burked01 0:5dc28ed27b01 50 }
burked01 0:5dc28ed27b01 51
burked01 0:5dc28ed27b01 52 void maxOne(int maxNr, int reg, int col) {
burked01 0:5dc28ed27b01 53 //maxOne is for adressing different MAX7219's,
burked01 0:5dc28ed27b01 54 //while having a couple of them cascaded
burked01 0:5dc28ed27b01 55 int c = 0;
burked01 0:5dc28ed27b01 56 load = LOW;
burked01 0:5dc28ed27b01 57
burked01 0:5dc28ed27b01 58 for ( c = maxInUse; c > maxNr; c--) {
burked01 0:5dc28ed27b01 59 max72_spi.write(0); // no-op
burked01 0:5dc28ed27b01 60 max72_spi.write(0); // no-op
burked01 0:5dc28ed27b01 61 }
burked01 0:5dc28ed27b01 62
burked01 0:5dc28ed27b01 63 max72_spi.write(reg); // specify register
burked01 0:5dc28ed27b01 64 max72_spi.write(col); // put data
burked01 0:5dc28ed27b01 65
burked01 0:5dc28ed27b01 66 for ( c=maxNr-1; c >= 1; c--) {
burked01 0:5dc28ed27b01 67 max72_spi.write(0); // no-op
burked01 0:5dc28ed27b01 68 max72_spi.write(0); // no-op
burked01 0:5dc28ed27b01 69 }
burked01 0:5dc28ed27b01 70 load = HIGH;
burked01 0:5dc28ed27b01 71 }
burked01 0:5dc28ed27b01 72
burked01 0:5dc28ed27b01 73
burked01 0:5dc28ed27b01 74
burked01 0:5dc28ed27b01 75 void setup () {
burked01 0:5dc28ed27b01 76 // initiation of the max 7219
burked01 0:5dc28ed27b01 77 // SPI setup: 8 bits, mode 0
burked01 0:5dc28ed27b01 78 max72_spi.format(8, 0);
burked01 0:5dc28ed27b01 79
burked01 0:5dc28ed27b01 80 // going by the datasheet, min clk is 100ns so theoretically 10MHz should work...
burked01 0:5dc28ed27b01 81 max72_spi.frequency(10*MHZ);
burked01 0:5dc28ed27b01 82
burked01 0:5dc28ed27b01 83 maxAll(max7219_reg_scanLimit, 0x07);
burked01 0:5dc28ed27b01 84 maxAll(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
burked01 0:5dc28ed27b01 85 maxAll(max7219_reg_shutdown, 0x01); // not in shutdown mode
burked01 0:5dc28ed27b01 86 maxAll(max7219_reg_displayTest, 0x00); // no display test
burked01 0:5dc28ed27b01 87 for (int e=1; e<=8; e++) { // empty registers, turn all LEDs off
burked01 0:5dc28ed27b01 88 maxAll(e,0);
burked01 0:5dc28ed27b01 89 }
burked01 0:5dc28ed27b01 90 maxAll(max7219_reg_intensity, 0x01 & 0x0f); // the first 0x0f is the value you can set
burked01 0:5dc28ed27b01 91 // range: 0x00 to 0x0f
burked01 0:5dc28ed27b01 92 }
burked01 0:5dc28ed27b01 93
burked01 0:5dc28ed27b01 94
burked01 0:5dc28ed27b01 95
burked01 0:5dc28ed27b01 96 int getBitValue(int bit)
burked01 0:5dc28ed27b01 97 {
burked01 0:5dc28ed27b01 98 pc.printf("bit = %d\n\r", bit);
burked01 0:5dc28ed27b01 99 switch(bit)
burked01 0:5dc28ed27b01 100 {
burked01 0:5dc28ed27b01 101 case 0: return 1;
burked01 0:5dc28ed27b01 102 case 1: return 2;
burked01 0:5dc28ed27b01 103 case 2: return 4;
burked01 0:5dc28ed27b01 104 case 3: return 8;
burked01 0:5dc28ed27b01 105 case 4: return 16;
burked01 0:5dc28ed27b01 106 case 5: return 32;
burked01 0:5dc28ed27b01 107 case 6: return 64;
burked01 0:5dc28ed27b01 108 case 7: return 128;
burked01 0:5dc28ed27b01 109 }
burked01 0:5dc28ed27b01 110 return 0;
burked01 0:5dc28ed27b01 111 }
burked01 0:5dc28ed27b01 112 void interpret(string data, int maxId, int rowId)
burked01 0:5dc28ed27b01 113 {
burked01 0:5dc28ed27b01 114 int value = 0;
burked01 0:5dc28ed27b01 115 for(int c=0;c<8;c++)
burked01 0:5dc28ed27b01 116 {
burked01 0:5dc28ed27b01 117 if(data.substr(c,1) == "+")
burked01 0:5dc28ed27b01 118 {
burked01 0:5dc28ed27b01 119 value += getBitValue(c);
burked01 0:5dc28ed27b01 120 pc.printf("value = %d\n\r",value);
burked01 0:5dc28ed27b01 121 }
burked01 0:5dc28ed27b01 122 }
burked01 0:5dc28ed27b01 123 pc.printf("value = %d\n\r",value);
burked01 0:5dc28ed27b01 124 maxOne(maxId, rowId ,value);
burked01 0:5dc28ed27b01 125 }
burked01 0:5dc28ed27b01 126
burked01 0:5dc28ed27b01 127 int _GameMode1 = 1;
burked01 0:5dc28ed27b01 128 int _GameMode2 = 2;
burked01 0:5dc28ed27b01 129 int _GameMode3 = 3;
burked01 0:5dc28ed27b01 130 int _GameMode4 = 4;
burked01 0:5dc28ed27b01 131 int _Step1 = 0;
burked01 0:5dc28ed27b01 132 int _MaxStep1 = 1;
burked01 0:5dc28ed27b01 133 int _Step2 = 0;
burked01 0:5dc28ed27b01 134 int _MaxStep2 = 1;
burked01 0:5dc28ed27b01 135 int _Step3 = 0;
burked01 0:5dc28ed27b01 136 int _MaxStep3 = 1;
burked01 0:5dc28ed27b01 137 int _Step4 = 0;
burked01 0:5dc28ed27b01 138 int _MaxStep4 = 1;
burked01 0:5dc28ed27b01 139 int _Step5 = 0;
burked01 0:5dc28ed27b01 140 int _MaxStep5 = 1;
burked01 0:5dc28ed27b01 141 int _LastGameMode1 = 0;
burked01 0:5dc28ed27b01 142 int _LastGameMode2 = 0;
burked01 0:5dc28ed27b01 143 int _LastGameMode3 = 0;
burked01 0:5dc28ed27b01 144 int _LastGameMode4 = 0;
burked01 0:5dc28ed27b01 145
burked01 0:5dc28ed27b01 146 void Mode1(int index)
burked01 0:5dc28ed27b01 147 {
burked01 0:5dc28ed27b01 148 switch(index)
burked01 0:5dc28ed27b01 149 {
burked01 0:5dc28ed27b01 150 case 1:
burked01 0:5dc28ed27b01 151 if(_LastGameMode1 != 1)
burked01 0:5dc28ed27b01 152 {
burked01 0:5dc28ed27b01 153 _Step1 = 0;
burked01 0:5dc28ed27b01 154 _MaxStep1 = 9;
burked01 0:5dc28ed27b01 155 _LastGameMode1 = _GameMode1;
burked01 0:5dc28ed27b01 156 }
burked01 0:5dc28ed27b01 157 break;
burked01 0:5dc28ed27b01 158 case 2:
burked01 0:5dc28ed27b01 159 if(_LastGameMode2 != 1)
burked01 0:5dc28ed27b01 160 {
burked01 0:5dc28ed27b01 161 _Step1 = 0;
burked01 0:5dc28ed27b01 162 _MaxStep1 = 9;
burked01 0:5dc28ed27b01 163 _LastGameMode2 = _GameMode2;
burked01 0:5dc28ed27b01 164 }
burked01 0:5dc28ed27b01 165 break;
burked01 0:5dc28ed27b01 166 case 3:
burked01 0:5dc28ed27b01 167 if(_LastGameMode3 != 1)
burked01 0:5dc28ed27b01 168 {
burked01 0:5dc28ed27b01 169 _Step1 = 0;
burked01 0:5dc28ed27b01 170 _MaxStep1 = 9;
burked01 0:5dc28ed27b01 171 _LastGameMode3 = _GameMode3;
burked01 0:5dc28ed27b01 172 }
burked01 0:5dc28ed27b01 173 break;
burked01 0:5dc28ed27b01 174 case 4:
burked01 0:5dc28ed27b01 175 if(_LastGameMode4 != 1)
burked01 0:5dc28ed27b01 176 {
burked01 0:5dc28ed27b01 177 _Step1 = 0;
burked01 0:5dc28ed27b01 178 _MaxStep1 = 9;
burked01 0:5dc28ed27b01 179 _LastGameMode4 = _GameMode4;
burked01 0:5dc28ed27b01 180 }
burked01 0:5dc28ed27b01 181 break;
burked01 0:5dc28ed27b01 182 }
burked01 0:5dc28ed27b01 183 switch(_Step1)
burked01 0:5dc28ed27b01 184 {
burked01 0:5dc28ed27b01 185 while (_Step1 ==1) {
burked01 0:5dc28ed27b01 186 case 0:
burked01 0:5dc28ed27b01 187 interpret("--------",index,1);
burked01 0:5dc28ed27b01 188 interpret("----+---",index,2);
burked01 0:5dc28ed27b01 189 interpret("----+---",index,3);
burked01 0:5dc28ed27b01 190 interpret("----+---",index,4);
burked01 0:5dc28ed27b01 191 interpret("----+---",index,5);
burked01 0:5dc28ed27b01 192 interpret("----+---",index,6);
burked01 0:5dc28ed27b01 193 interpret("--------",index,7);
burked01 0:5dc28ed27b01 194 interpret("--------",index,8);
burked01 0:5dc28ed27b01 195 break;
burked01 0:5dc28ed27b01 196 case 1:
burked01 0:5dc28ed27b01 197 interpret("--------",index,1);
burked01 0:5dc28ed27b01 198 interpret("--------",index,2);
burked01 0:5dc28ed27b01 199 interpret("--------",index,3);
burked01 0:5dc28ed27b01 200 interpret("--------",index,4);
burked01 0:5dc28ed27b01 201 interpret("--------",index,5);
burked01 0:5dc28ed27b01 202 interpret("--------",index,6);
burked01 0:5dc28ed27b01 203 interpret("--------",index,7);
burked01 0:5dc28ed27b01 204 interpret("--------",index,8);
burked01 0:5dc28ed27b01 205 break;
burked01 0:5dc28ed27b01 206
burked01 0:5dc28ed27b01 207 }
burked01 0:5dc28ed27b01 208 }
burked01 0:5dc28ed27b01 209 wait_ms(20);
burked01 0:5dc28ed27b01 210 }
burked01 0:5dc28ed27b01 211 void Mode2(int index)
burked01 0:5dc28ed27b01 212 {
burked01 0:5dc28ed27b01 213 switch(index)
burked01 0:5dc28ed27b01 214 {
burked01 0:5dc28ed27b01 215 case 1:
burked01 0:5dc28ed27b01 216 if(_LastGameMode1 != 2)
burked01 0:5dc28ed27b01 217 {
burked01 0:5dc28ed27b01 218 _Step2 = 0;
burked01 0:5dc28ed27b01 219 _MaxStep2 = 9;
burked01 0:5dc28ed27b01 220 _LastGameMode1 = _GameMode1;
burked01 0:5dc28ed27b01 221 }
burked01 0:5dc28ed27b01 222 break;
burked01 0:5dc28ed27b01 223 case 2:
burked01 0:5dc28ed27b01 224 if(_LastGameMode2 != 2)
burked01 0:5dc28ed27b01 225 {
burked01 0:5dc28ed27b01 226 _Step2 = 0;
burked01 0:5dc28ed27b01 227 _MaxStep2 = 9;
burked01 0:5dc28ed27b01 228 _LastGameMode2 = _GameMode2;
burked01 0:5dc28ed27b01 229 }
burked01 0:5dc28ed27b01 230 break;
burked01 0:5dc28ed27b01 231 case 3:
burked01 0:5dc28ed27b01 232 if(_LastGameMode3 != 2)
burked01 0:5dc28ed27b01 233 {
burked01 0:5dc28ed27b01 234 _Step2 = 0;
burked01 0:5dc28ed27b01 235 _MaxStep2 = 9;
burked01 0:5dc28ed27b01 236 _LastGameMode3 = _GameMode3;
burked01 0:5dc28ed27b01 237 }
burked01 0:5dc28ed27b01 238 break;
burked01 0:5dc28ed27b01 239 case 4:
burked01 0:5dc28ed27b01 240 if(_LastGameMode4 != 2)
burked01 0:5dc28ed27b01 241 {
burked01 0:5dc28ed27b01 242 _Step2 = 0;
burked01 0:5dc28ed27b01 243 _MaxStep2 = 9;
burked01 0:5dc28ed27b01 244 _LastGameMode4 = _GameMode4;
burked01 0:5dc28ed27b01 245 }
burked01 0:5dc28ed27b01 246 break;
burked01 0:5dc28ed27b01 247 }
burked01 0:5dc28ed27b01 248
burked01 0:5dc28ed27b01 249 switch(_Step2)
burked01 0:5dc28ed27b01 250 {
burked01 0:5dc28ed27b01 251 case 0:
burked01 0:5dc28ed27b01 252 interpret("--------",index,1);
burked01 0:5dc28ed27b01 253 interpret("-++++++-",index,2);
burked01 0:5dc28ed27b01 254 interpret("-+-----",index,3);
burked01 0:5dc28ed27b01 255 interpret("-++++++-",index,4);
burked01 0:5dc28ed27b01 256 interpret("------+-",index,5);
burked01 0:5dc28ed27b01 257 interpret("-++++++-",index,6);
burked01 0:5dc28ed27b01 258 interpret("--------",index,7);
burked01 0:5dc28ed27b01 259 interpret("--------",index,8);
burked01 0:5dc28ed27b01 260 break;
burked01 0:5dc28ed27b01 261 case 1:
burked01 0:5dc28ed27b01 262 interpret("--------",index,1);
burked01 0:5dc28ed27b01 263 interpret("--------",index,2);
burked01 0:5dc28ed27b01 264 interpret("--------",index,3);
burked01 0:5dc28ed27b01 265 interpret("--------",index,4);
burked01 0:5dc28ed27b01 266 interpret("--------",index,5);
burked01 0:5dc28ed27b01 267 interpret("--------",index,6);
burked01 0:5dc28ed27b01 268 interpret("--------",index,7);
burked01 0:5dc28ed27b01 269 interpret("--------",index,8);
burked01 0:5dc28ed27b01 270 break;
burked01 0:5dc28ed27b01 271
burked01 0:5dc28ed27b01 272 }
burked01 0:5dc28ed27b01 273 wait_ms(5);
burked01 0:5dc28ed27b01 274 }
burked01 0:5dc28ed27b01 275 void Mode3(int index)
burked01 0:5dc28ed27b01 276 {
burked01 0:5dc28ed27b01 277 switch(index)
burked01 0:5dc28ed27b01 278 {
burked01 0:5dc28ed27b01 279 case 1:
burked01 0:5dc28ed27b01 280 if(_LastGameMode1 != 3)
burked01 0:5dc28ed27b01 281 {
burked01 0:5dc28ed27b01 282 _Step3 = 0;
burked01 0:5dc28ed27b01 283 _MaxStep3 = 9;
burked01 0:5dc28ed27b01 284 _LastGameMode1 = _GameMode1;
burked01 0:5dc28ed27b01 285 }
burked01 0:5dc28ed27b01 286 break;
burked01 0:5dc28ed27b01 287 case 2:
burked01 0:5dc28ed27b01 288 if(_LastGameMode2 != 3)
burked01 0:5dc28ed27b01 289 {
burked01 0:5dc28ed27b01 290 _Step3 = 0;
burked01 0:5dc28ed27b01 291 _MaxStep3 = 9;
burked01 0:5dc28ed27b01 292 _LastGameMode2 = _GameMode2;
burked01 0:5dc28ed27b01 293 }
burked01 0:5dc28ed27b01 294 break;
burked01 0:5dc28ed27b01 295 case 3:
burked01 0:5dc28ed27b01 296 if(_LastGameMode3 != 3)
burked01 0:5dc28ed27b01 297 {
burked01 0:5dc28ed27b01 298 _Step3 = 0;
burked01 0:5dc28ed27b01 299 _MaxStep3 = 9;
burked01 0:5dc28ed27b01 300 _LastGameMode3 = _GameMode3;
burked01 0:5dc28ed27b01 301 }
burked01 0:5dc28ed27b01 302 break;
burked01 0:5dc28ed27b01 303 case 4:
burked01 0:5dc28ed27b01 304 if(_LastGameMode4 != 3)
burked01 0:5dc28ed27b01 305 {
burked01 0:5dc28ed27b01 306 _Step3 = 0;
burked01 0:5dc28ed27b01 307 _MaxStep3 = 9;
burked01 0:5dc28ed27b01 308 _LastGameMode4 = _GameMode4;
burked01 0:5dc28ed27b01 309 }
burked01 0:5dc28ed27b01 310 break;
burked01 0:5dc28ed27b01 311 }
burked01 0:5dc28ed27b01 312
burked01 0:5dc28ed27b01 313 switch(_Step3)
burked01 0:5dc28ed27b01 314 {
burked01 0:5dc28ed27b01 315 case 0:
burked01 0:5dc28ed27b01 316 interpret("--------",index,1);
burked01 0:5dc28ed27b01 317 interpret("-++++++-",index,2);
burked01 0:5dc28ed27b01 318 interpret("------+-",index,3);
burked01 0:5dc28ed27b01 319 interpret("-++++++-",index,4);
burked01 0:5dc28ed27b01 320 interpret("------+-",index,5);
burked01 0:5dc28ed27b01 321 interpret("-++++++-",index,6);
burked01 0:5dc28ed27b01 322 interpret("--------",index,7);
burked01 0:5dc28ed27b01 323 interpret("--------",index,8);
burked01 0:5dc28ed27b01 324 break;
burked01 0:5dc28ed27b01 325 case 1:
burked01 0:5dc28ed27b01 326 interpret("--------",index,1);
burked01 0:5dc28ed27b01 327 interpret("--------",index,2);
burked01 0:5dc28ed27b01 328 interpret("--------",index,3);
burked01 0:5dc28ed27b01 329 interpret("--------",index,4);
burked01 0:5dc28ed27b01 330 interpret("--------",index,5);
burked01 0:5dc28ed27b01 331 interpret("--------",index,6);
burked01 0:5dc28ed27b01 332 interpret("--------",index,7);
burked01 0:5dc28ed27b01 333 interpret("--------",index,8);
burked01 0:5dc28ed27b01 334 break;
burked01 0:5dc28ed27b01 335
burked01 0:5dc28ed27b01 336 }
burked01 0:5dc28ed27b01 337 wait_ms(5);
burked01 0:5dc28ed27b01 338 }
burked01 0:5dc28ed27b01 339 void Mode4(int index)
burked01 0:5dc28ed27b01 340 {
burked01 0:5dc28ed27b01 341 switch(index)
burked01 0:5dc28ed27b01 342 {
burked01 0:5dc28ed27b01 343 case 1:
burked01 0:5dc28ed27b01 344 if(_LastGameMode1 != 4)
burked01 0:5dc28ed27b01 345 {
burked01 0:5dc28ed27b01 346 _Step4 = 0;
burked01 0:5dc28ed27b01 347 _MaxStep4 = 9;
burked01 0:5dc28ed27b01 348 _LastGameMode1 = _GameMode1;
burked01 0:5dc28ed27b01 349 }
burked01 0:5dc28ed27b01 350 break;
burked01 0:5dc28ed27b01 351 case 2:
burked01 0:5dc28ed27b01 352 if(_LastGameMode2 != 4)
burked01 0:5dc28ed27b01 353 {
burked01 0:5dc28ed27b01 354 _Step4 = 0;
burked01 0:5dc28ed27b01 355 _MaxStep4 = 9;
burked01 0:5dc28ed27b01 356 _LastGameMode2 = _GameMode2;
burked01 0:5dc28ed27b01 357 }
burked01 0:5dc28ed27b01 358 break;
burked01 0:5dc28ed27b01 359 case 3:
burked01 0:5dc28ed27b01 360 if(_LastGameMode3 != 4)
burked01 0:5dc28ed27b01 361 {
burked01 0:5dc28ed27b01 362 _Step4 = 0;
burked01 0:5dc28ed27b01 363 _MaxStep4 = 9;
burked01 0:5dc28ed27b01 364 _LastGameMode3 = _GameMode3;
burked01 0:5dc28ed27b01 365 }
burked01 0:5dc28ed27b01 366 break;
burked01 0:5dc28ed27b01 367 case 4:
burked01 0:5dc28ed27b01 368 if(_LastGameMode4 != 4)
burked01 0:5dc28ed27b01 369 {
burked01 0:5dc28ed27b01 370 _Step4 = 0;
burked01 0:5dc28ed27b01 371 _MaxStep4 = 9;
burked01 0:5dc28ed27b01 372 _LastGameMode4 = _GameMode4;
burked01 0:5dc28ed27b01 373 }
burked01 0:5dc28ed27b01 374 break;
burked01 0:5dc28ed27b01 375 }
burked01 0:5dc28ed27b01 376 switch(_Step4)
burked01 0:5dc28ed27b01 377 {
burked01 0:5dc28ed27b01 378 case 0:
burked01 0:5dc28ed27b01 379 interpret("--------",index,1);
burked01 0:5dc28ed27b01 380 interpret("------+-",index,2);
burked01 0:5dc28ed27b01 381 interpret("------+-",index,3);
burked01 0:5dc28ed27b01 382 interpret("-++++++-",index,4);
burked01 0:5dc28ed27b01 383 interpret("-+----+-",index,5);
burked01 0:5dc28ed27b01 384 interpret("-+----+-",index,6);
burked01 0:5dc28ed27b01 385 interpret("--------",index,7);
burked01 0:5dc28ed27b01 386 interpret("--------",index,8);
burked01 0:5dc28ed27b01 387
burked01 0:5dc28ed27b01 388 break;
burked01 0:5dc28ed27b01 389
burked01 0:5dc28ed27b01 390 case 1:
burked01 0:5dc28ed27b01 391 interpret("--------",index,1);
burked01 0:5dc28ed27b01 392 interpret("--------",index,2);
burked01 0:5dc28ed27b01 393 interpret("--------",index,3);
burked01 0:5dc28ed27b01 394 interpret("--------",index,4);
burked01 0:5dc28ed27b01 395 interpret("--------",index,5);
burked01 0:5dc28ed27b01 396 interpret("--------",index,6);
burked01 0:5dc28ed27b01 397 interpret("--------",index,7);
burked01 0:5dc28ed27b01 398 interpret("--------",index,8);
burked01 0:5dc28ed27b01 399 break;
burked01 0:5dc28ed27b01 400
burked01 0:5dc28ed27b01 401 }
burked01 0:5dc28ed27b01 402 wait_ms(5);
burked01 0:5dc28ed27b01 403 }
burked01 0:5dc28ed27b01 404
burked01 0:5dc28ed27b01 405
burked01 0:5dc28ed27b01 406 int MAX_MODE = 4;
burked01 0:5dc28ed27b01 407 void pressed()
burked01 0:5dc28ed27b01 408 {
burked01 0:5dc28ed27b01 409 _GameMode1++;
burked01 0:5dc28ed27b01 410 if(_GameMode1 > MAX_MODE) _GameMode1 = 1;
burked01 0:5dc28ed27b01 411 _GameMode2++;
burked01 0:5dc28ed27b01 412 if(_GameMode2 > MAX_MODE) _GameMode2 = 1;
burked01 0:5dc28ed27b01 413 _GameMode3++;
burked01 0:5dc28ed27b01 414 if(_GameMode3 > MAX_MODE) _GameMode3 = 1;
burked01 0:5dc28ed27b01 415 _GameMode4++;
burked01 0:5dc28ed27b01 416 if(_GameMode4 > MAX_MODE) _GameMode4 = 1;
burked01 0:5dc28ed27b01 417 }
burked01 0:5dc28ed27b01 418
burked01 0:5dc28ed27b01 419 void DisplayGameMode()
burked01 0:5dc28ed27b01 420 {
burked01 0:5dc28ed27b01 421 switch(_GameMode1)
burked01 0:5dc28ed27b01 422 {
burked01 0:5dc28ed27b01 423 case 1: Mode1(1); break;
burked01 0:5dc28ed27b01 424 case 2: Mode2(1); break;
burked01 0:5dc28ed27b01 425 case 3: Mode3(1); break;
burked01 0:5dc28ed27b01 426 case 4: Mode4(1); break;
burked01 0:5dc28ed27b01 427 }
burked01 0:5dc28ed27b01 428 switch(_GameMode2)
burked01 0:5dc28ed27b01 429 {
burked01 0:5dc28ed27b01 430 case 1: Mode1(2); break;
burked01 0:5dc28ed27b01 431 case 2: Mode2(2); break;
burked01 0:5dc28ed27b01 432 case 3: Mode3(2); break;
burked01 0:5dc28ed27b01 433 case 4: Mode4(2); break;
burked01 0:5dc28ed27b01 434 }
burked01 0:5dc28ed27b01 435 switch(_GameMode3)
burked01 0:5dc28ed27b01 436 {
burked01 0:5dc28ed27b01 437 case 1: Mode1(3); break;
burked01 0:5dc28ed27b01 438 case 2: Mode2(3); break;
burked01 0:5dc28ed27b01 439 case 3: Mode3(3); break;
burked01 0:5dc28ed27b01 440 case 4: Mode4(3); break;
burked01 0:5dc28ed27b01 441 }
burked01 0:5dc28ed27b01 442 switch(_GameMode4)
burked01 0:5dc28ed27b01 443 {
burked01 0:5dc28ed27b01 444 case 1: Mode1(4); break;
burked01 0:5dc28ed27b01 445 case 2: Mode2(4); break;
burked01 0:5dc28ed27b01 446 case 3: Mode3(4); break;
burked01 0:5dc28ed27b01 447 case 4: Mode4(4); break;
burked01 0:5dc28ed27b01 448 }
burked01 0:5dc28ed27b01 449 _Step1++;
burked01 0:5dc28ed27b01 450 if(_Step1 > _MaxStep1)_Step1 = 0;
burked01 0:5dc28ed27b01 451 _Step2++;
burked01 0:5dc28ed27b01 452 if(_Step2 > _MaxStep2)_Step2 = 0;
burked01 0:5dc28ed27b01 453 _Step3++;
burked01 0:5dc28ed27b01 454 if(_Step3 > _MaxStep3)_Step3 = 0;
burked01 0:5dc28ed27b01 455 _Step4++;
burked01 0:5dc28ed27b01 456 if(_Step4 > _MaxStep4)_Step4 = 0;
burked01 0:5dc28ed27b01 457
burked01 0:5dc28ed27b01 458
burked01 0:5dc28ed27b01 459 }
burked01 0:5dc28ed27b01 460 int main() {
burked01 0:5dc28ed27b01 461 mybutton.fall(&pressed);
burked01 0:5dc28ed27b01 462 srand (time(NULL));
burked01 0:5dc28ed27b01 463 setup ();
burked01 0:5dc28ed27b01 464 while(true){DisplayGameMode();}
burked01 0:5dc28ed27b01 465 }