Whack a Mole game! Features: - LCD graphics display - Touch pad input - Speaker effects through a class D audio amplifier\ - A high score page maintained by the SD card file system - Analog noise used to seed random numbers
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed
Fork of MPR121_Demo by
main.cpp@9:867dde4be88a, 2016-03-14 (annotated)
- Committer:
- tpettet3
- Date:
- Mon Mar 14 18:50:39 2016 +0000
- Revision:
- 9:867dde4be88a
- Parent:
- 8:e6e1e5b3f2a9
- Child:
- 10:a31802412ab6
commented and fully functional;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:e09703934ff4 | 1 | /* |
4180_1 | 0:e09703934ff4 | 2 | Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au) |
4180_1 | 0:e09703934ff4 | 3 | |
4180_1 | 0:e09703934ff4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
4180_1 | 0:e09703934ff4 | 5 | of this software and associated documentation files (the "Software"), to deal |
4180_1 | 0:e09703934ff4 | 6 | in the Software without restriction, including without limitation the rights |
4180_1 | 0:e09703934ff4 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
4180_1 | 0:e09703934ff4 | 8 | copies of the Software, and to permit persons to whom the Software is |
4180_1 | 0:e09703934ff4 | 9 | furnished to do so, subject to the following conditions: |
4180_1 | 0:e09703934ff4 | 10 | |
4180_1 | 0:e09703934ff4 | 11 | The above copyright notice and this permission notice shall be included in |
4180_1 | 0:e09703934ff4 | 12 | all copies or substantial portions of the Software. |
4180_1 | 0:e09703934ff4 | 13 | |
4180_1 | 0:e09703934ff4 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
4180_1 | 0:e09703934ff4 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
4180_1 | 0:e09703934ff4 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
4180_1 | 0:e09703934ff4 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
4180_1 | 0:e09703934ff4 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
4180_1 | 0:e09703934ff4 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
4180_1 | 0:e09703934ff4 | 20 | THE SOFTWARE. |
4180_1 | 0:e09703934ff4 | 21 | */ |
4180_1 | 0:e09703934ff4 | 22 | |
4180_1 | 0:e09703934ff4 | 23 | #include <mbed.h> |
4180_1 | 0:e09703934ff4 | 24 | #include <string> |
4180_1 | 0:e09703934ff4 | 25 | #include <list> |
tpettet3 | 1:89fd0d713ffc | 26 | #include "uLCD_4DGL.h" |
tpettet3 | 1:89fd0d713ffc | 27 | #include <mpr121.h> |
tpettet3 | 5:070755be0a77 | 28 | #include "SDFileSystem.h" |
tpettet3 | 5:070755be0a77 | 29 | #include "SongPlayer.h" |
tpettet3 | 9:867dde4be88a | 30 | |
tpettet3 | 9:867dde4be88a | 31 | //initialize lcd |
tpettet3 | 1:89fd0d713ffc | 32 | uLCD_4DGL lcd(p9, p10, p30); // tx, rx, reset |
4180_1 | 0:e09703934ff4 | 33 | |
4180_1 | 0:e09703934ff4 | 34 | DigitalOut led1(LED1); |
4180_1 | 0:e09703934ff4 | 35 | DigitalOut led2(LED2); |
4180_1 | 0:e09703934ff4 | 36 | DigitalOut led3(LED3); |
4180_1 | 0:e09703934ff4 | 37 | DigitalOut led4(LED4); |
tpettet3 | 9:867dde4be88a | 38 | |
tpettet3 | 9:867dde4be88a | 39 | //setup analog in pin to read noise for random number generation |
tpettet3 | 1:89fd0d713ffc | 40 | AnalogIn Ain(p15); |
4180_1 | 0:e09703934ff4 | 41 | |
tpettet3 | 8:e6e1e5b3f2a9 | 42 | //Setup class D audio output on pwm out pin |
tpettet3 | 6:ca03b9c94c88 | 43 | SongPlayer mySpeaker(p21); |
tpettet3 | 8:e6e1e5b3f2a9 | 44 | |
tpettet3 | 9:867dde4be88a | 45 | //Create the interrupt receiver object on pin 26 |
4180_1 | 0:e09703934ff4 | 46 | InterruptIn interrupt(p26); |
tpettet3 | 8:e6e1e5b3f2a9 | 47 | |
tpettet3 | 8:e6e1e5b3f2a9 | 48 | //Setup the Serial to the PC for debugging |
4180_1 | 0:e09703934ff4 | 49 | Serial pc(USBTX, USBRX); |
tpettet3 | 8:e6e1e5b3f2a9 | 50 | |
tpettet3 | 8:e6e1e5b3f2a9 | 51 | //setup SD card filesystem |
tpettet3 | 8:e6e1e5b3f2a9 | 52 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
tpettet3 | 8:e6e1e5b3f2a9 | 53 | |
4180_1 | 0:e09703934ff4 | 54 | // Setup the i2c bus on pins 28 and 27 |
tpettet3 | 1:89fd0d713ffc | 55 | I2C i2c(p28, p27); |
tpettet3 | 8:e6e1e5b3f2a9 | 56 | |
tpettet3 | 8:e6e1e5b3f2a9 | 57 | //setup the note to be played upon hitting a mole |
tpettet3 | 5:070755be0a77 | 58 | float note[1]= {1568.0}; |
tpettet3 | 5:070755be0a77 | 59 | float duration[1]= {0.1}; |
tpettet3 | 8:e6e1e5b3f2a9 | 60 | |
tpettet3 | 8:e6e1e5b3f2a9 | 61 | //initialize the possition integers |
tpettet3 | 1:89fd0d713ffc | 62 | int pos1; |
tpettet3 | 1:89fd0d713ffc | 63 | int pos2; |
tpettet3 | 1:89fd0d713ffc | 64 | int pos3; |
tpettet3 | 1:89fd0d713ffc | 65 | int pos4; |
tpettet3 | 1:89fd0d713ffc | 66 | int pos5; |
tpettet3 | 1:89fd0d713ffc | 67 | int pos6; |
tpettet3 | 8:e6e1e5b3f2a9 | 68 | |
tpettet3 | 8:e6e1e5b3f2a9 | 69 | //initialize global variable to keep track of the score |
tpettet3 | 1:89fd0d713ffc | 70 | int score = 0; |
tpettet3 | 8:e6e1e5b3f2a9 | 71 | |
tpettet3 | 8:e6e1e5b3f2a9 | 72 | //create variables for the keypad outputs that correspond to mole possitions |
tpettet3 | 1:89fd0d713ffc | 73 | int hole1 = 0x100; |
tpettet3 | 1:89fd0d713ffc | 74 | int hole2 = 0x10; |
tpettet3 | 1:89fd0d713ffc | 75 | int hole3 = 0x1; |
tpettet3 | 1:89fd0d713ffc | 76 | int hole4 = 0x200; |
tpettet3 | 1:89fd0d713ffc | 77 | int hole5 = 0x20; |
tpettet3 | 1:89fd0d713ffc | 78 | int hole6 = 0x2; |
tpettet3 | 8:e6e1e5b3f2a9 | 79 | |
tpettet3 | 8:e6e1e5b3f2a9 | 80 | //create a character buffer to read from the SD card |
tpettet3 | 5:070755be0a77 | 81 | char str [80]; |
tpettet3 | 8:e6e1e5b3f2a9 | 82 | |
4180_1 | 0:e09703934ff4 | 83 | // Setup the Mpr121: |
4180_1 | 0:e09703934ff4 | 84 | // constructor(i2c object, i2c address of the mpr121) |
4180_1 | 0:e09703934ff4 | 85 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
4180_1 | 0:e09703934ff4 | 86 | |
4180_1 | 0:e09703934ff4 | 87 | void fallInterrupt() { |
4180_1 | 0:e09703934ff4 | 88 | int key_code=0; |
4180_1 | 0:e09703934ff4 | 89 | int i=0; |
tpettet3 | 8:e6e1e5b3f2a9 | 90 | |
tpettet3 | 8:e6e1e5b3f2a9 | 91 | //read values from keypad after interupt and bitshift left 8 times |
4180_1 | 0:e09703934ff4 | 92 | int value=mpr121.read(0x00); |
4180_1 | 0:e09703934ff4 | 93 | value +=mpr121.read(0x01)<<8; |
tpettet3 | 8:e6e1e5b3f2a9 | 94 | //Check to see if the a mole is hit after an interupt |
tpettet3 | 3:dbae62823ec8 | 95 | if (value==256&&pos1==1) |
tpettet3 | 3:dbae62823ec8 | 96 | { |
tpettet3 | 9:867dde4be88a | 97 | mySpeaker.PlaySong(note,duration);//play note to indicate successful hit |
tpettet3 | 9:867dde4be88a | 98 | score++;//increment score by one |
tpettet3 | 8:e6e1e5b3f2a9 | 99 | pos1 = 0;//set the position to 0 after succesful hit to prevent multiple hits |
tpettet3 | 3:dbae62823ec8 | 100 | } |
tpettet3 | 3:dbae62823ec8 | 101 | if (value==16&&pos2==1) |
tpettet3 | 3:dbae62823ec8 | 102 | { |
tpettet3 | 6:ca03b9c94c88 | 103 | mySpeaker.PlaySong(note,duration); |
tpettet3 | 3:dbae62823ec8 | 104 | score++; |
tpettet3 | 7:5a8f9a018e1f | 105 | pos2 = 0; |
tpettet3 | 3:dbae62823ec8 | 106 | } |
tpettet3 | 3:dbae62823ec8 | 107 | if (value==1&&pos3==1) |
tpettet3 | 6:ca03b9c94c88 | 108 | { |
tpettet3 | 6:ca03b9c94c88 | 109 | mySpeaker.PlaySong(note,duration); |
tpettet3 | 1:89fd0d713ffc | 110 | score++; |
tpettet3 | 7:5a8f9a018e1f | 111 | pos3 = 0; |
tpettet3 | 1:89fd0d713ffc | 112 | } |
tpettet3 | 3:dbae62823ec8 | 113 | if (value==512&&pos4==1) |
tpettet3 | 3:dbae62823ec8 | 114 | { |
tpettet3 | 6:ca03b9c94c88 | 115 | mySpeaker.PlaySong(note,duration); |
tpettet3 | 3:dbae62823ec8 | 116 | score++; |
tpettet3 | 7:5a8f9a018e1f | 117 | pos4 = 0; |
tpettet3 | 3:dbae62823ec8 | 118 | } |
tpettet3 | 3:dbae62823ec8 | 119 | if (value==32&&pos5==1) |
tpettet3 | 3:dbae62823ec8 | 120 | { |
tpettet3 | 6:ca03b9c94c88 | 121 | mySpeaker.PlaySong(note,duration); |
tpettet3 | 3:dbae62823ec8 | 122 | score++; |
tpettet3 | 7:5a8f9a018e1f | 123 | pos5 = 0; |
tpettet3 | 3:dbae62823ec8 | 124 | } |
tpettet3 | 3:dbae62823ec8 | 125 | if (value==2&&pos6==1) |
tpettet3 | 3:dbae62823ec8 | 126 | { |
tpettet3 | 6:ca03b9c94c88 | 127 | mySpeaker.PlaySong(note,duration); |
tpettet3 | 3:dbae62823ec8 | 128 | score++; |
tpettet3 | 7:5a8f9a018e1f | 129 | pos6 = 0; |
tpettet3 | 3:dbae62823ec8 | 130 | } |
4180_1 | 0:e09703934ff4 | 131 | } |
tpettet3 | 9:867dde4be88a | 132 | float arand;// variable to store analog noise |
tpettet3 | 9:867dde4be88a | 133 | unsigned int state; // global state variable |
tpettet3 | 1:89fd0d713ffc | 134 | |
4180_1 | 0:e09703934ff4 | 135 | int main() { |
tpettet3 | 9:867dde4be88a | 136 | lcd.baudrate(300000);// set lcd baudrate |
tpettet3 | 1:89fd0d713ffc | 137 | |
tpettet3 | 1:89fd0d713ffc | 138 | int out = 0xFF0000;// outline color |
tpettet3 | 1:89fd0d713ffc | 139 | int fill = 0x0000;// fill color. aka no mole |
tpettet3 | 1:89fd0d713ffc | 140 | int col1 = 21; |
tpettet3 | 1:89fd0d713ffc | 141 | int col2 = 64; |
tpettet3 | 1:89fd0d713ffc | 142 | int col3=107; |
tpettet3 | 4:4cb02cde783c | 143 | int row3=107; |
tpettet3 | 1:89fd0d713ffc | 144 | int row2=64; |
tpettet3 | 4:4cb02cde783c | 145 | int row1=21; |
tpettet3 | 1:89fd0d713ffc | 146 | int r = 20; |
tpettet3 | 1:89fd0d713ffc | 147 | int rmole=18;//radius mole |
tpettet3 | 1:89fd0d713ffc | 148 | int mole= 0xD3D3D3;//mole color like gray |
tpettet3 | 1:89fd0d713ffc | 149 | |
tpettet3 | 9:867dde4be88a | 150 | lcd.circle(col1, row1 , r, out);// draws 6 circles to the lcd screen to show where the moles will appear |
tpettet3 | 1:89fd0d713ffc | 151 | lcd.circle(col1, row2 , r, out); |
tpettet3 | 1:89fd0d713ffc | 152 | lcd.circle(col2, row1 , r, out); |
tpettet3 | 1:89fd0d713ffc | 153 | lcd.circle(col2, row2 , r, out); |
tpettet3 | 1:89fd0d713ffc | 154 | lcd.circle(col3, row1 , r, out); |
tpettet3 | 1:89fd0d713ffc | 155 | lcd.circle(col3, row2 , r, out); |
4180_1 | 0:e09703934ff4 | 156 | |
tpettet3 | 9:867dde4be88a | 157 | // Begin test code for mpr121 |
tpettet3 | 9:867dde4be88a | 158 | pc.printf("\nHello from the mbed & mpr121\n\r"); |
4180_1 | 0:e09703934ff4 | 159 | |
tpettet3 | 9:867dde4be88a | 160 | unsigned char dataArray[2]; |
tpettet3 | 9:867dde4be88a | 161 | int key; |
tpettet3 | 9:867dde4be88a | 162 | int count = 0; |
4180_1 | 0:e09703934ff4 | 163 | |
tpettet3 | 9:867dde4be88a | 164 | pc.printf("Test 1: read a value: \r\n"); |
tpettet3 | 9:867dde4be88a | 165 | dataArray[0] = mpr121.read(AFE_CFG); |
4180_1 | 0:e09703934ff4 | 166 | pc.printf("Read value=%x\r\n\n",dataArray[0]); |
4180_1 | 0:e09703934ff4 | 167 | |
4180_1 | 0:e09703934ff4 | 168 | pc.printf("Test 2: read a value: \r\n"); |
4180_1 | 0:e09703934ff4 | 169 | dataArray[0] = mpr121.read(0x5d); |
4180_1 | 0:e09703934ff4 | 170 | pc.printf("Read value=%x\r\n\n",dataArray[0]); |
4180_1 | 0:e09703934ff4 | 171 | |
4180_1 | 0:e09703934ff4 | 172 | pc.printf("Test 3: write & read a value: \r\n"); |
4180_1 | 0:e09703934ff4 | 173 | mpr121.read(ELE0_T); |
4180_1 | 0:e09703934ff4 | 174 | mpr121.write(ELE0_T,0x22); |
4180_1 | 0:e09703934ff4 | 175 | dataArray[0] = mpr121.read(ELE0_T); |
4180_1 | 0:e09703934ff4 | 176 | pc.printf("Read value=%x\r\n\n",dataArray[0]); |
4180_1 | 0:e09703934ff4 | 177 | |
4180_1 | 0:e09703934ff4 | 178 | pc.printf("Test 4: Write many values: \r\n"); |
4180_1 | 0:e09703934ff4 | 179 | unsigned char data[] = {0x1,0x3,0x5,0x9,0x15,0x25,0x41}; |
4180_1 | 0:e09703934ff4 | 180 | mpr121.writeMany(0x42,data,7); |
4180_1 | 0:e09703934ff4 | 181 | |
4180_1 | 0:e09703934ff4 | 182 | // Now read them back .. |
4180_1 | 0:e09703934ff4 | 183 | key = 0x42; |
4180_1 | 0:e09703934ff4 | 184 | count = 0; |
4180_1 | 0:e09703934ff4 | 185 | while (count < 7) { |
4180_1 | 0:e09703934ff4 | 186 | char result = mpr121.read(key); |
4180_1 | 0:e09703934ff4 | 187 | key++; |
4180_1 | 0:e09703934ff4 | 188 | count++; |
4180_1 | 0:e09703934ff4 | 189 | pc.printf("Read value: '%x'=%x\n\r",key,result); |
4180_1 | 0:e09703934ff4 | 190 | } |
4180_1 | 0:e09703934ff4 | 191 | |
4180_1 | 0:e09703934ff4 | 192 | pc.printf("Test 5: Read Electrodes:\r\n"); |
4180_1 | 0:e09703934ff4 | 193 | key = ELE0_T; |
4180_1 | 0:e09703934ff4 | 194 | count = 0; |
4180_1 | 0:e09703934ff4 | 195 | while (count < 24) { |
4180_1 | 0:e09703934ff4 | 196 | char result = mpr121.read(key); |
4180_1 | 0:e09703934ff4 | 197 | pc.printf("Read key:%x value:%x\n\r",key,result); |
4180_1 | 0:e09703934ff4 | 198 | key++; |
4180_1 | 0:e09703934ff4 | 199 | count++; |
4180_1 | 0:e09703934ff4 | 200 | } |
4180_1 | 0:e09703934ff4 | 201 | pc.printf("--------- \r\n\n"); |
4180_1 | 0:e09703934ff4 | 202 | |
4180_1 | 0:e09703934ff4 | 203 | // mpr121.setProximityMode(true); |
4180_1 | 0:e09703934ff4 | 204 | |
4180_1 | 0:e09703934ff4 | 205 | pc.printf("ELE_CFG=%x", mpr121.read(ELE_CFG)); |
tpettet3 | 9:867dde4be88a | 206 | // end test code of mpr121 |
4180_1 | 0:e09703934ff4 | 207 | |
tpettet3 | 9:867dde4be88a | 208 | |
tpettet3 | 9:867dde4be88a | 209 | interrupt.fall(&fallInterrupt);//set up the interrupt mode |
4180_1 | 0:e09703934ff4 | 210 | interrupt.mode(PullUp); |
tpettet3 | 9:867dde4be88a | 211 | |
tpettet3 | 9:867dde4be88a | 212 | int counter = 0;// initialize the variable to count the number of transitions per game |
tpettet3 | 9:867dde4be88a | 213 | |
tpettet3 | 9:867dde4be88a | 214 | //read in a psuedo random noise reading and multiply so that it can later be cast to int by truncation |
tpettet3 | 9:867dde4be88a | 215 | arand = Ain.read()*1000000; |
tpettet3 | 9:867dde4be88a | 216 | |
tpettet3 | 9:867dde4be88a | 217 | //seed rand with noise reading |
tpettet3 | 9:867dde4be88a | 218 | srand(arand); |
tpettet3 | 9:867dde4be88a | 219 | |
tpettet3 | 9:867dde4be88a | 220 | //game runs for transitions |
tpettet3 | 8:e6e1e5b3f2a9 | 221 | while (counter < 30) { |
tpettet3 | 8:e6e1e5b3f2a9 | 222 | |
tpettet3 | 9:867dde4be88a | 223 | //determine state using rand() |
tpettet3 | 1:89fd0d713ffc | 224 | state = rand()%15; |
tpettet3 | 9:867dde4be88a | 225 | |
tpettet3 | 9:867dde4be88a | 226 | //switch the value of state to determine the output to the lcd |
tpettet3 | 1:89fd0d713ffc | 227 | switch(state) |
tpettet3 | 1:89fd0d713ffc | 228 | { |
tpettet3 | 1:89fd0d713ffc | 229 | case 0: |
tpettet3 | 9:867dde4be88a | 230 | //mutex functionality can be incorperated my uncommenting //POS_MUTEX.un/lock() |
tpettet3 | 3:dbae62823ec8 | 231 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 232 | pos1=1; |
tpettet3 | 1:89fd0d713ffc | 233 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 234 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 235 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 236 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 237 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 238 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 239 | pc.printf("%i should be 0 \n\r",state); |
tpettet3 | 9:867dde4be88a | 240 | lcd.filled_circle(col1, row1 , rmole, fill);// 1 |
tpettet3 | 9:867dde4be88a | 241 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 242 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 243 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 244 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 245 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 246 | lcd.filled_circle(col1, row1 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 247 | break; |
tpettet3 | 1:89fd0d713ffc | 248 | case 1: |
tpettet3 | 3:dbae62823ec8 | 249 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 250 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 251 | pos2=1; |
tpettet3 | 1:89fd0d713ffc | 252 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 253 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 254 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 255 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 256 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 257 | pc.printf("%i should be 1 \n\r",state); |
tpettet3 | 9:867dde4be88a | 258 | lcd.filled_circle(col1, row1 , rmole, fill);// 2 |
tpettet3 | 9:867dde4be88a | 259 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 260 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 261 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 262 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 263 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 264 | lcd.filled_circle(col2, row1 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 265 | break; |
tpettet3 | 1:89fd0d713ffc | 266 | case 2: |
tpettet3 | 3:dbae62823ec8 | 267 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 268 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 269 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 270 | pos3=1; |
tpettet3 | 1:89fd0d713ffc | 271 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 272 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 273 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 274 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 275 | pc.printf("%i should be 2 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 276 | lcd.filled_circle(col1, row1 , rmole, fill);// 3 |
tpettet3 | 9:867dde4be88a | 277 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 278 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 279 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 280 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 281 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 282 | lcd.filled_circle(col3, row1 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 283 | break; |
tpettet3 | 1:89fd0d713ffc | 284 | case 3: |
tpettet3 | 3:dbae62823ec8 | 285 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 286 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 287 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 288 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 289 | pos4=1; |
tpettet3 | 1:89fd0d713ffc | 290 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 291 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 292 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 293 | pc.printf("%i should be 3 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 294 | lcd.filled_circle(col1, row1 , rmole, fill);// 4 |
tpettet3 | 9:867dde4be88a | 295 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 296 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 297 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 298 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 299 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 300 | lcd.filled_circle(col1, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 301 | break; |
tpettet3 | 1:89fd0d713ffc | 302 | case 4: |
tpettet3 | 3:dbae62823ec8 | 303 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 304 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 305 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 306 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 307 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 308 | pos5=1; |
tpettet3 | 1:89fd0d713ffc | 309 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 310 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 311 | pc.printf("%i should be 4 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 312 | lcd.filled_circle(col1, row1 , rmole, fill);// 5 |
tpettet3 | 9:867dde4be88a | 313 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 314 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 315 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 316 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 317 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 318 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 319 | break; |
tpettet3 | 1:89fd0d713ffc | 320 | case 5: |
tpettet3 | 3:dbae62823ec8 | 321 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 322 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 323 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 324 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 325 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 326 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 327 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 328 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 329 | pc.printf("%i should be 5 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 330 | |
tpettet3 | 9:867dde4be88a | 331 | lcd.filled_circle(col1, row1 , rmole, fill);// 6 |
tpettet3 | 9:867dde4be88a | 332 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 333 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 334 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 335 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 336 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 337 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 338 | break; |
tpettet3 | 1:89fd0d713ffc | 339 | case 6: |
tpettet3 | 3:dbae62823ec8 | 340 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 341 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 342 | pos2=1; |
tpettet3 | 1:89fd0d713ffc | 343 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 344 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 345 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 346 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 347 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 348 | pc.printf("%i should be 6 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 349 | lcd.filled_circle(col1, row1 , rmole, fill);// 2,6 |
tpettet3 | 9:867dde4be88a | 350 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 351 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 352 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 353 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 354 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 355 | lcd.filled_circle(col2, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 356 | lcd.filled_circle(col3, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 357 | break; |
tpettet3 | 1:89fd0d713ffc | 358 | case 7: |
tpettet3 | 3:dbae62823ec8 | 359 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 360 | pos1=1; |
tpettet3 | 1:89fd0d713ffc | 361 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 362 | pos3=1; |
tpettet3 | 1:89fd0d713ffc | 363 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 364 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 365 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 366 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 367 | pc.printf("%i should be 7 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 368 | lcd.filled_circle(col1, row1 , rmole, fill);// 1,3 |
tpettet3 | 9:867dde4be88a | 369 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 370 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 371 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 372 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 373 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 374 | lcd.filled_circle(col1, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 375 | lcd.filled_circle(col3, row1 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 376 | break; |
tpettet3 | 1:89fd0d713ffc | 377 | case 8: |
tpettet3 | 3:dbae62823ec8 | 378 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 379 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 380 | pos2=1; |
tpettet3 | 1:89fd0d713ffc | 381 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 382 | pos4=1; |
tpettet3 | 1:89fd0d713ffc | 383 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 384 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 385 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 386 | pc.printf("%i should be 8 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 387 | |
tpettet3 | 9:867dde4be88a | 388 | lcd.filled_circle(col1, row1 , rmole, fill);// 2,4,6 |
tpettet3 | 9:867dde4be88a | 389 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 390 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 391 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 392 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 393 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 394 | lcd.filled_circle(col2, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 395 | lcd.filled_circle(col1, row2 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 396 | lcd.filled_circle(col3, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 397 | break; |
tpettet3 | 1:89fd0d713ffc | 398 | case 9: |
tpettet3 | 3:dbae62823ec8 | 399 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 400 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 401 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 402 | pos3=1; |
tpettet3 | 1:89fd0d713ffc | 403 | pos4=1; |
tpettet3 | 1:89fd0d713ffc | 404 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 405 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 406 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 407 | pc.printf("%i should be 9 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 408 | lcd.filled_circle(col1, row1 , rmole, fill);// 3,4,6 |
tpettet3 | 9:867dde4be88a | 409 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 410 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 411 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 412 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 413 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 414 | lcd.filled_circle(col3, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 415 | lcd.filled_circle(col1, row2 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 416 | lcd.filled_circle(col3, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 417 | break; |
tpettet3 | 1:89fd0d713ffc | 418 | case 10: |
tpettet3 | 3:dbae62823ec8 | 419 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 420 | pos1=1; |
tpettet3 | 1:89fd0d713ffc | 421 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 422 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 423 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 424 | pos5=0; |
tpettet3 | 1:89fd0d713ffc | 425 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 426 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 427 | pc.printf("%i should be 10 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 428 | lcd.filled_circle(col1, row1 , rmole, fill);// 1,6 |
tpettet3 | 9:867dde4be88a | 429 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 430 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 431 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 432 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 433 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 434 | lcd.filled_circle(col1, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 435 | lcd.filled_circle(col3, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 436 | break; |
tpettet3 | 1:89fd0d713ffc | 437 | case 11: |
tpettet3 | 3:dbae62823ec8 | 438 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 439 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 440 | pos2=1; |
tpettet3 | 1:89fd0d713ffc | 441 | pos3=1; |
tpettet3 | 1:89fd0d713ffc | 442 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 443 | pos5=1; |
tpettet3 | 1:89fd0d713ffc | 444 | pos6=1; |
tpettet3 | 3:dbae62823ec8 | 445 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 446 | pc.printf("%i should be 11 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 447 | lcd.filled_circle(col1, row1 , rmole, fill);// 2,3,5,6 |
tpettet3 | 9:867dde4be88a | 448 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 449 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 450 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 451 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 452 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 453 | lcd.filled_circle(col2, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 454 | lcd.filled_circle(col3, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 455 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 456 | lcd.filled_circle(col3, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 457 | break; |
tpettet3 | 1:89fd0d713ffc | 458 | case 12: |
tpettet3 | 3:dbae62823ec8 | 459 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 460 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 461 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 462 | pos3=1; |
tpettet3 | 1:89fd0d713ffc | 463 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 464 | pos5=1; |
tpettet3 | 1:89fd0d713ffc | 465 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 466 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 467 | pc.printf("%i should be 12 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 468 | lcd.filled_circle(col1, row1 , rmole, fill);// 3,5 |
tpettet3 | 9:867dde4be88a | 469 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 470 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 471 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 472 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 473 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 474 | lcd.filled_circle(col3, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 475 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 476 | break; |
tpettet3 | 1:89fd0d713ffc | 477 | case 13: |
tpettet3 | 3:dbae62823ec8 | 478 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 479 | pos1=1; |
tpettet3 | 1:89fd0d713ffc | 480 | pos2=0; |
tpettet3 | 1:89fd0d713ffc | 481 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 482 | pos4=1; |
tpettet3 | 1:89fd0d713ffc | 483 | pos5=1; |
tpettet3 | 1:89fd0d713ffc | 484 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 485 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 486 | pc.printf("%i should be 13 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 487 | lcd.filled_circle(col1, row1 , rmole, fill);// 1,4,5 |
tpettet3 | 9:867dde4be88a | 488 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 489 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 490 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 491 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 492 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 493 | lcd.filled_circle(col1, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 494 | lcd.filled_circle(col1, row2 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 495 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 496 | break; |
tpettet3 | 1:89fd0d713ffc | 497 | case 14: |
tpettet3 | 3:dbae62823ec8 | 498 | //POS_MUTEX.lock(); |
tpettet3 | 1:89fd0d713ffc | 499 | pos1=0; |
tpettet3 | 1:89fd0d713ffc | 500 | pos2=1; |
tpettet3 | 1:89fd0d713ffc | 501 | pos3=0; |
tpettet3 | 1:89fd0d713ffc | 502 | pos4=0; |
tpettet3 | 1:89fd0d713ffc | 503 | pos5=1; |
tpettet3 | 1:89fd0d713ffc | 504 | pos6=0; |
tpettet3 | 3:dbae62823ec8 | 505 | //POS_MUTEX.unlock(); |
tpettet3 | 1:89fd0d713ffc | 506 | pc.printf("%i should be 14 \n\r",state); |
tpettet3 | 1:89fd0d713ffc | 507 | |
tpettet3 | 9:867dde4be88a | 508 | lcd.filled_circle(col1, row1 , rmole, fill);// 2,5 |
tpettet3 | 9:867dde4be88a | 509 | lcd.filled_circle(col1, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 510 | lcd.filled_circle(col2, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 511 | lcd.filled_circle(col2, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 512 | lcd.filled_circle(col3, row1 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 513 | lcd.filled_circle(col3, row2 , rmole, fill); |
tpettet3 | 9:867dde4be88a | 514 | lcd.filled_circle(col2, row1 , rmole, mole); |
tpettet3 | 9:867dde4be88a | 515 | lcd.filled_circle(col2, row2 , rmole, mole); |
tpettet3 | 1:89fd0d713ffc | 516 | break; |
tpettet3 | 1:89fd0d713ffc | 517 | } |
tpettet3 | 8:e6e1e5b3f2a9 | 518 | wait(0.5); |
tpettet3 | 9:867dde4be88a | 519 | counter++; // increment counter and run the "state machine again" |
tpettet3 | 5:070755be0a77 | 520 | } |
tpettet3 | 9:867dde4be88a | 521 | // clear the lcd screen |
tpettet3 | 9:867dde4be88a | 522 | lcd.cls(); |
tpettet3 | 9:867dde4be88a | 523 | wait(0.5); |
tpettet3 | 9:867dde4be88a | 524 | lcd.cls(); |
tpettet3 | 9:867dde4be88a | 525 | // int variable to read current high score |
tpettet3 | 7:5a8f9a018e1f | 526 | int please; |
tpettet3 | 7:5a8f9a018e1f | 527 | mkdir("/sd/mydir", 0777); |
tpettet3 | 7:5a8f9a018e1f | 528 | FILE *fp1 = fopen("/sd/mydir/sdtest.txt", "r"); |
tpettet3 | 7:5a8f9a018e1f | 529 | if(fp1 == NULL) |
tpettet3 | 7:5a8f9a018e1f | 530 | { |
tpettet3 | 7:5a8f9a018e1f | 531 | pc.printf("Could not open file for read\n"); |
tpettet3 | 7:5a8f9a018e1f | 532 | } |
tpettet3 | 7:5a8f9a018e1f | 533 | pc.printf("Opened file for read\n\r"); |
tpettet3 | 7:5a8f9a018e1f | 534 | fscanf (fp1, "%s", str); |
tpettet3 | 7:5a8f9a018e1f | 535 | sscanf(str, "%d", &please); |
tpettet3 | 7:5a8f9a018e1f | 536 | fclose(fp1); |
tpettet3 | 8:e6e1e5b3f2a9 | 537 | pc.printf (": %d \n",please); |
tpettet3 | 8:e6e1e5b3f2a9 | 538 | if (score > please) |
tpettet3 | 8:e6e1e5b3f2a9 | 539 | { |
tpettet3 | 8:e6e1e5b3f2a9 | 540 | FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); |
tpettet3 | 8:e6e1e5b3f2a9 | 541 | if(fp == NULL) { |
tpettet3 | 7:5a8f9a018e1f | 542 | error("Could not open file for write\n"); |
tpettet3 | 7:5a8f9a018e1f | 543 | } |
tpettet3 | 7:5a8f9a018e1f | 544 | char buf[10]; |
tpettet3 | 8:e6e1e5b3f2a9 | 545 | sprintf(buf, "%d", score); |
tpettet3 | 7:5a8f9a018e1f | 546 | fprintf(fp, "%s",buf); |
tpettet3 | 7:5a8f9a018e1f | 547 | fclose(fp); |
tpettet3 | 8:e6e1e5b3f2a9 | 548 | lcd.printf("CONGRATULATIONS!\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 549 | lcd.printf("You set the new\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 550 | lcd.printf("High score!!!!!!\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 551 | lcd.printf("New high score: %d\n\n",score); |
tpettet3 | 8:e6e1e5b3f2a9 | 552 | lcd.printf("Press reset to\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 553 | lcd.printf("Play Again!"); |
tpettet3 | 8:e6e1e5b3f2a9 | 554 | } |
tpettet3 | 8:e6e1e5b3f2a9 | 555 | else |
tpettet3 | 8:e6e1e5b3f2a9 | 556 | { |
tpettet3 | 8:e6e1e5b3f2a9 | 557 | lcd.printf("High score: %d\n\n",please); |
tpettet3 | 8:e6e1e5b3f2a9 | 558 | lcd.printf("Your score: %d\n\n",score); |
tpettet3 | 8:e6e1e5b3f2a9 | 559 | lcd.printf("You did not set\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 560 | lcd.printf("A new high score\n\n"); |
tpettet3 | 8:e6e1e5b3f2a9 | 561 | lcd.printf("Press reset to\n\n"); |
tpettet3 | 9:867dde4be88a | 562 | lcd.printf("Try again"); |
tpettet3 | 8:e6e1e5b3f2a9 | 563 | } |
tpettet3 | 8:e6e1e5b3f2a9 | 564 | |
tpettet3 | 9:867dde4be88a | 565 | pc.printf("Goodbye World!\n"); |
tpettet3 | 9:867dde4be88a | 566 | }//end |
4180_1 | 0:e09703934ff4 | 567 | |
4180_1 | 0:e09703934ff4 | 568 | |
4180_1 | 0:e09703934ff4 | 569 | |
tpettet3 | 1:89fd0d713ffc | 570 |