Bluetooth
Dependencies: 4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player
main.cpp@3:2499b6bda80f, 23 months ago (annotated)
- Committer:
- jwalker366
- Date:
- Mon Dec 05 04:19:54 2022 +0000
- Revision:
- 3:2499b6bda80f
- Parent:
- 2:655c8a5c2ad8
Did alot. well go over it tomorrow
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ridwangs7 | 1:f264a7ecd285 | 1 | /* |
ridwangs7 | 1:f264a7ecd285 | 2 | Jared Walker |
ridwangs7 | 1:f264a7ecd285 | 3 | Ridwan Sadiq |
ridwangs7 | 1:f264a7ecd285 | 4 | Emanuel Abdul-Salaam |
ridwangs7 | 1:f264a7ecd285 | 5 | Juan Padilla |
ridwangs7 | 1:f264a7ecd285 | 6 | */ |
jwalker366 | 2:655c8a5c2ad8 | 7 | #include <time.h> /* time_t, struct tm, difftime, time, mktime */ |
jwalker366 | 2:655c8a5c2ad8 | 8 | #include <ctime> |
jwalker366 | 0:088af403d779 | 9 | #include "mbed.h" |
ridwangs7 | 1:f264a7ecd285 | 10 | #include "uLCD_4DGL.h" |
jwalker366 | 3:2499b6bda80f | 11 | //#include "SDFileSystem.h" |
jwalker366 | 3:2499b6bda80f | 12 | #include "SDFileSystem.h" |
jwalker366 | 3:2499b6bda80f | 13 | #include "wave_player.h" |
jwalker366 | 3:2499b6bda80f | 14 | #include "PinDetect.h" |
jwalker366 | 3:2499b6bda80f | 15 | #include "MMA8452.h" |
jwalker366 | 3:2499b6bda80f | 16 | #include "Speaker.h" |
ridwangs7 | 1:f264a7ecd285 | 17 | |
jwalker366 | 2:655c8a5c2ad8 | 18 | MMA8452 acc(p28, p27, 40000); //instantiate an acc object |
ridwangs7 | 1:f264a7ecd285 | 19 | BusOut myled(LED1,LED2,LED3,LED4); |
ridwangs7 | 1:f264a7ecd285 | 20 | Serial blue(p9,p10); |
ridwangs7 | 1:f264a7ecd285 | 21 | Serial pc(USBTX, USBRX); |
ridwangs7 | 1:f264a7ecd285 | 22 | uLCD_4DGL ulcd(p13,p14,p11); |
jwalker366 | 3:2499b6bda80f | 23 | DigitalIn pb2(p24);//check later if thats ok |
jwalker366 | 3:2499b6bda80f | 24 | DigitalIn pb1(p25);//check later if thats ok |
jwalker366 | 3:2499b6bda80f | 25 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board |
jwalker366 | 3:2499b6bda80f | 26 | AnalogOut speaker(p26); |
jwalker366 | 3:2499b6bda80f | 27 | wave_player waver(&speaker); |
ridwangs7 | 1:f264a7ecd285 | 28 | |
jwalker366 | 3:2499b6bda80f | 29 | int screenBreak = 0; |
jwalker366 | 3:2499b6bda80f | 30 | int but_pushed1 = 0; // ==1 -> pb1 pushed, == 2 -> pb2 pushed |
jwalker366 | 3:2499b6bda80f | 31 | int but_pushed2 = 0; |
ridwangs7 | 1:f264a7ecd285 | 32 | bool selectedDiceArray[5]; |
jwalker366 | 3:2499b6bda80f | 33 | int faceValCarry[5]; |
jwalker366 | 3:2499b6bda80f | 34 | int randoArray[5]; |
jwalker366 | 3:2499b6bda80f | 35 | int accFlag = 0; // this is gonna be the variable that the accelerometer flips to roll the dice |
ridwangs7 | 1:f264a7ecd285 | 36 | |
jwalker366 | 0:088af403d779 | 37 | |
ridwangs7 | 1:f264a7ecd285 | 38 | int selectDice() |
ridwangs7 | 1:f264a7ecd285 | 39 | { |
ridwangs7 | 1:f264a7ecd285 | 40 | char bnum=0; |
ridwangs7 | 1:f264a7ecd285 | 41 | char bhit=0; |
ridwangs7 | 1:f264a7ecd285 | 42 | int diceNum = 0; |
ridwangs7 | 1:f264a7ecd285 | 43 | |
ridwangs7 | 1:f264a7ecd285 | 44 | if (blue.getc()=='!') { |
ridwangs7 | 1:f264a7ecd285 | 45 | if (blue.getc()=='B') { //button data packet |
ridwangs7 | 1:f264a7ecd285 | 46 | bnum = blue.getc(); //button number |
ridwangs7 | 1:f264a7ecd285 | 47 | bhit = blue.getc(); //1=hit, 0=release |
ridwangs7 | 1:f264a7ecd285 | 48 | if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? |
ridwangs7 | 1:f264a7ecd285 | 49 | if ((bnum>='1')&&(bnum<='5')){ //is a number button 1..4 |
ridwangs7 | 1:f264a7ecd285 | 50 | diceNum = bnum-48; |
ridwangs7 | 1:f264a7ecd285 | 51 | selectedDiceArray[diceNum]= 1; |
ridwangs7 | 1:f264a7ecd285 | 52 | if (bhit=='1') { |
ridwangs7 | 1:f264a7ecd285 | 53 | myled = bnum - '0'; |
ridwangs7 | 1:f264a7ecd285 | 54 | } else { |
ridwangs7 | 1:f264a7ecd285 | 55 | myled = '0'; |
ridwangs7 | 1:f264a7ecd285 | 56 | } |
ridwangs7 | 1:f264a7ecd285 | 57 | } |
ridwangs7 | 1:f264a7ecd285 | 58 | } |
ridwangs7 | 1:f264a7ecd285 | 59 | } |
ridwangs7 | 1:f264a7ecd285 | 60 | } |
ridwangs7 | 1:f264a7ecd285 | 61 | return diceNum; |
ridwangs7 | 1:f264a7ecd285 | 62 | } |
ridwangs7 | 1:f264a7ecd285 | 63 | |
ridwangs7 | 1:f264a7ecd285 | 64 | |
ridwangs7 | 1:f264a7ecd285 | 65 | void draw_start(){ |
ridwangs7 | 1:f264a7ecd285 | 66 | ulcd.text_width(2); |
ridwangs7 | 1:f264a7ecd285 | 67 | ulcd.text_height(2); |
ridwangs7 | 1:f264a7ecd285 | 68 | ulcd.locate(2,2); |
ridwangs7 | 1:f264a7ecd285 | 69 | ulcd.printf("\n YAHTZEE"); |
ridwangs7 | 1:f264a7ecd285 | 70 | |
ridwangs7 | 1:f264a7ecd285 | 71 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 72 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 73 | ulcd.locate(4,8); |
ridwangs7 | 1:f264a7ecd285 | 74 | ulcd.printf("\n Press to Roll"); |
ridwangs7 | 1:f264a7ecd285 | 75 | |
ridwangs7 | 1:f264a7ecd285 | 76 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 77 | |
ridwangs7 | 1:f264a7ecd285 | 78 | |
ridwangs7 | 1:f264a7ecd285 | 79 | } |
ridwangs7 | 1:f264a7ecd285 | 80 | |
jwalker366 | 3:2499b6bda80f | 81 | void shaking_sound() { |
jwalker366 | 3:2499b6bda80f | 82 | FILE *wave_file; |
jwalker366 | 3:2499b6bda80f | 83 | //open wav file and play it |
jwalker366 | 3:2499b6bda80f | 84 | wave_file=fopen("/sd/thread_sound.wav","r"); |
jwalker366 | 3:2499b6bda80f | 85 | waver.play(wave_file); |
jwalker366 | 3:2499b6bda80f | 86 | fclose(wave_file); |
jwalker366 | 3:2499b6bda80f | 87 | //end of program |
jwalker366 | 3:2499b6bda80f | 88 | wait(.2); |
jwalker366 | 3:2499b6bda80f | 89 | } |
jwalker366 | 0:088af403d779 | 90 | |
ridwangs7 | 1:f264a7ecd285 | 91 | void draw_readyRoll(){ |
ridwangs7 | 1:f264a7ecd285 | 92 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 93 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 94 | ulcd.locate(4,1); |
ridwangs7 | 1:f264a7ecd285 | 95 | ulcd.printf("\n Ready to Roll"); |
ridwangs7 | 1:f264a7ecd285 | 96 | |
ridwangs7 | 1:f264a7ecd285 | 97 | ulcd.text_width(2); |
ridwangs7 | 1:f264a7ecd285 | 98 | ulcd.text_height(2); |
ridwangs7 | 1:f264a7ecd285 | 99 | ulcd.locate(2,1); |
ridwangs7 | 1:f264a7ecd285 | 100 | ulcd.printf("\n Press\n Roll\n Button\n to Roll"); |
ridwangs7 | 1:f264a7ecd285 | 101 | |
ridwangs7 | 1:f264a7ecd285 | 102 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 103 | |
ridwangs7 | 1:f264a7ecd285 | 104 | |
ridwangs7 | 1:f264a7ecd285 | 105 | } |
ridwangs7 | 1:f264a7ecd285 | 106 | |
ridwangs7 | 1:f264a7ecd285 | 107 | |
ridwangs7 | 1:f264a7ecd285 | 108 | void draw_diceDisp(){ |
ridwangs7 | 1:f264a7ecd285 | 109 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 110 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 111 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 112 | ulcd.printf("Do you want to select any dice?"); |
ridwangs7 | 1:f264a7ecd285 | 113 | |
ridwangs7 | 1:f264a7ecd285 | 114 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 115 | |
ridwangs7 | 1:f264a7ecd285 | 116 | |
ridwangs7 | 1:f264a7ecd285 | 117 | } |
ridwangs7 | 1:f264a7ecd285 | 118 | |
jwalker366 | 3:2499b6bda80f | 119 | int roll(){ |
jwalker366 | 3:2499b6bda80f | 120 | |
jwalker366 | 3:2499b6bda80f | 121 | int rando = (rand()%6)+1; |
jwalker366 | 3:2499b6bda80f | 122 | |
jwalker366 | 3:2499b6bda80f | 123 | return rando; |
jwalker366 | 3:2499b6bda80f | 124 | } |
ridwangs7 | 1:f264a7ecd285 | 125 | |
ridwangs7 | 1:f264a7ecd285 | 126 | void draw_diceSelect(){ |
ridwangs7 | 1:f264a7ecd285 | 127 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 128 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 129 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 130 | ulcd.printf("Press button 1 to roll again"); |
ridwangs7 | 1:f264a7ecd285 | 131 | ulcd.printf("\n Press button 2 to break"); |
ridwangs7 | 1:f264a7ecd285 | 132 | |
ridwangs7 | 1:f264a7ecd285 | 133 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 134 | |
ridwangs7 | 1:f264a7ecd285 | 135 | |
ridwangs7 | 1:f264a7ecd285 | 136 | } |
ridwangs7 | 1:f264a7ecd285 | 137 | |
ridwangs7 | 1:f264a7ecd285 | 138 | |
ridwangs7 | 1:f264a7ecd285 | 139 | void draw_scoreScreen(){ |
jwalker366 | 3:2499b6bda80f | 140 | // I think we should add "ulcd.cls;" to declutter the screen sometimes, or print a black background |
ridwangs7 | 1:f264a7ecd285 | 141 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 142 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 143 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 144 | ulcd.printf("Please score your round and reset."); |
ridwangs7 | 1:f264a7ecd285 | 145 | |
ridwangs7 | 1:f264a7ecd285 | 146 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 147 | |
ridwangs7 | 1:f264a7ecd285 | 148 | |
ridwangs7 | 1:f264a7ecd285 | 149 | } |
ridwangs7 | 1:f264a7ecd285 | 150 | |
jwalker366 | 2:655c8a5c2ad8 | 151 | // This fuctuion prints a single dice to the screen, but can be used over and over to print every dice |
jwalker366 | 3:2499b6bda80f | 152 | int xarry[] = {22,22,64,64,105};//holds the center point for every dice on the X axis (for ulcd) |
jwalker366 | 3:2499b6bda80f | 153 | int yarry[] = {32,96,32,96,32};//holds the center point for every dice on the Y axis (for ulcd) |
jwalker366 | 3:2499b6bda80f | 154 | void diceLoc(int diceLoc,int diceFaceNum,int color)//diceLoc is the location of the dice (1-5) and diceFaceNum is the number on the dice face (provided by a random number gen |
jwalker366 | 2:655c8a5c2ad8 | 155 | { |
jwalker366 | 2:655c8a5c2ad8 | 156 | |
jwalker366 | 2:655c8a5c2ad8 | 157 | int x1=xarry[diceLoc] + 20; |
jwalker366 | 2:655c8a5c2ad8 | 158 | int x2=xarry[diceLoc] - 20; |
jwalker366 | 2:655c8a5c2ad8 | 159 | int y1=yarry[diceLoc] + 20; |
jwalker366 | 2:655c8a5c2ad8 | 160 | int y2=yarry[diceLoc] - 20; |
jwalker366 | 3:2499b6bda80f | 161 | if(color == 1){ |
jwalker366 | 3:2499b6bda80f | 162 | ulcd.rectangle(x1,y1,x2,y2,WHITE); |
jwalker366 | 3:2499b6bda80f | 163 | } |
jwalker366 | 3:2499b6bda80f | 164 | else if(color == 2){ |
jwalker366 | 3:2499b6bda80f | 165 | ulcd.rectangle(x1,y1,x2,y2,BLUE); |
jwalker366 | 3:2499b6bda80f | 166 | } |
jwalker366 | 2:655c8a5c2ad8 | 167 | switch(diceFaceNum){ |
jwalker366 | 2:655c8a5c2ad8 | 168 | case 1://if dice =1 |
jwalker366 | 3:2499b6bda80f | 169 | ulcd.filled_circle(xarry[diceLoc] , yarry[diceLoc] ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 170 | break; |
jwalker366 | 2:655c8a5c2ad8 | 171 | |
jwalker366 | 2:655c8a5c2ad8 | 172 | case 2://if dice =2 |
jwalker366 | 2:655c8a5c2ad8 | 173 | |
jwalker366 | 3:2499b6bda80f | 174 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10), 3, WHITE); |
jwalker366 | 3:2499b6bda80f | 175 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 176 | |
jwalker366 | 2:655c8a5c2ad8 | 177 | break; |
jwalker366 | 2:655c8a5c2ad8 | 178 | |
jwalker366 | 2:655c8a5c2ad8 | 179 | case 3://so on |
jwalker366 | 3:2499b6bda80f | 180 | ulcd.filled_circle((xarry[diceLoc]) , (yarry[diceLoc]) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 181 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 182 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc] - 10) ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 183 | |
jwalker366 | 2:655c8a5c2ad8 | 184 | break; |
jwalker366 | 2:655c8a5c2ad8 | 185 | |
jwalker366 | 2:655c8a5c2ad8 | 186 | case 4://so forth |
jwalker366 | 3:2499b6bda80f | 187 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 188 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 189 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+ 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 190 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 191 | |
jwalker366 | 2:655c8a5c2ad8 | 192 | break; |
jwalker366 | 2:655c8a5c2ad8 | 193 | |
jwalker366 | 2:655c8a5c2ad8 | 194 | case 5: |
jwalker366 | 2:655c8a5c2ad8 | 195 | |
jwalker366 | 3:2499b6bda80f | 196 | ulcd.filled_circle((xarry[diceLoc]) , (yarry[diceLoc]) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 197 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+ 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 198 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 199 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 200 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 201 | break; |
jwalker366 | 2:655c8a5c2ad8 | 202 | case 6: |
jwalker366 | 2:655c8a5c2ad8 | 203 | |
jwalker366 | 3:2499b6bda80f | 204 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 205 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 206 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+ 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 207 | ulcd.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 208 | ulcd.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]) ,3, WHITE); |
jwalker366 | 3:2499b6bda80f | 209 | ulcd.filled_circle((xarry[diceLoc]- 10 ) , (yarry[diceLoc]) ,3, WHITE); |
jwalker366 | 2:655c8a5c2ad8 | 210 | break; |
jwalker366 | 2:655c8a5c2ad8 | 211 | |
jwalker366 | 2:655c8a5c2ad8 | 212 | default: |
jwalker366 | 2:655c8a5c2ad8 | 213 | break; |
jwalker366 | 2:655c8a5c2ad8 | 214 | } |
jwalker366 | 3:2499b6bda80f | 215 | } |
jwalker366 | 2:655c8a5c2ad8 | 216 | //end dice printing function |
jwalker366 | 2:655c8a5c2ad8 | 217 | |
jwalker366 | 2:655c8a5c2ad8 | 218 | |
jwalker366 | 3:2499b6bda80f | 219 | void shakeDetect() |
jwalker366 | 3:2499b6bda80f | 220 | { |
jwalker366 | 2:655c8a5c2ad8 | 221 | acc.setBitDepth(MMA8452::BIT_DEPTH_12); |
jwalker366 | 2:655c8a5c2ad8 | 222 | acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); |
jwalker366 | 3:2499b6bda80f | 223 | acc.setDataRate(MMA8452::RATE_100);// dont worry about this garbage. it just sets some internal values for the acc |
jwalker366 | 2:655c8a5c2ad8 | 224 | double x = 0; |
jwalker366 | 3:2499b6bda80f | 225 | double y = 0; |
jwalker366 | 3:2499b6bda80f | 226 | |
jwalker366 | 3:2499b6bda80f | 227 | while(1) |
jwalker366 | 3:2499b6bda80f | 228 | { |
jwalker366 | 2:655c8a5c2ad8 | 229 | acc.readXGravity(&x); //notice this is passed by reference use pointers |
jwalker366 | 3:2499b6bda80f | 230 | acc.readYGravity(&y); |
jwalker366 | 3:2499b6bda80f | 231 | if(x >= .6 || y >= .6) |
jwalker366 | 3:2499b6bda80f | 232 | { |
jwalker366 | 3:2499b6bda80f | 233 | accFlag = 1; |
jwalker366 | 2:655c8a5c2ad8 | 234 | break; |
jwalker366 | 3:2499b6bda80f | 235 | } |
jwalker366 | 3:2499b6bda80f | 236 | } |
jwalker366 | 3:2499b6bda80f | 237 | |
jwalker366 | 3:2499b6bda80f | 238 | }// end acc stuff |
jwalker366 | 2:655c8a5c2ad8 | 239 | |
ridwangs7 | 1:f264a7ecd285 | 240 | int main() |
ridwangs7 | 1:f264a7ecd285 | 241 | { |
jwalker366 | 3:2499b6bda80f | 242 | |
ridwangs7 | 1:f264a7ecd285 | 243 | ulcd.cls(); |
ridwangs7 | 1:f264a7ecd285 | 244 | ulcd.baudrate(3000000); //jack up baud rate to max for fast display |
jwalker366 | 3:2499b6bda80f | 245 | //int selectedDice = 0; |
jwalker366 | 3:2499b6bda80f | 246 | |
jwalker366 | 3:2499b6bda80f | 247 | while(1) |
jwalker366 | 3:2499b6bda80f | 248 | { |
jwalker366 | 3:2499b6bda80f | 249 | draw_start(); |
jwalker366 | 3:2499b6bda80f | 250 | //audio needed here |
jwalker366 | 3:2499b6bda80f | 251 | |
jwalker366 | 3:2499b6bda80f | 252 | screenBreak = pb1; |
jwalker366 | 3:2499b6bda80f | 253 | if(screenBreak == 1) |
jwalker366 | 3:2499b6bda80f | 254 | { |
jwalker366 | 3:2499b6bda80f | 255 | break; |
jwalker366 | 3:2499b6bda80f | 256 | } |
jwalker366 | 3:2499b6bda80f | 257 | } |
jwalker366 | 3:2499b6bda80f | 258 | |
jwalker366 | 3:2499b6bda80f | 259 | screenBreak = 0; |
jwalker366 | 3:2499b6bda80f | 260 | |
jwalker366 | 3:2499b6bda80f | 261 | for (int j=0; 3 ;++j) |
jwalker366 | 3:2499b6bda80f | 262 | { //tbis is where the Game happens, breaks after j = 3 for three rounds |
jwalker366 | 3:2499b6bda80f | 263 | while(1) |
jwalker366 | 3:2499b6bda80f | 264 | { |
jwalker366 | 3:2499b6bda80f | 265 | draw_readyRoll(); |
jwalker366 | 3:2499b6bda80f | 266 | screenBreak = pb1; |
jwalker366 | 3:2499b6bda80f | 267 | shakeDetect(); |
jwalker366 | 3:2499b6bda80f | 268 | if (accFlag== 1 && screenBreak == 1) |
jwalker366 | 3:2499b6bda80f | 269 | { |
jwalker366 | 3:2499b6bda80f | 270 | break; |
jwalker366 | 3:2499b6bda80f | 271 | } |
jwalker366 | 3:2499b6bda80f | 272 | |
jwalker366 | 3:2499b6bda80f | 273 | } |
jwalker366 | 3:2499b6bda80f | 274 | accFlag = 0; |
jwalker366 | 3:2499b6bda80f | 275 | screenBreak = 0; |
jwalker366 | 3:2499b6bda80f | 276 | for(int k = 0; 5 ; ++k) |
jwalker366 | 3:2499b6bda80f | 277 | { |
jwalker366 | 3:2499b6bda80f | 278 | if(selectedDiceArray[k] == false) |
jwalker366 | 3:2499b6bda80f | 279 | { |
jwalker366 | 3:2499b6bda80f | 280 | randoArray[k] = roll(); |
jwalker366 | 3:2499b6bda80f | 281 | } |
jwalker366 | 3:2499b6bda80f | 282 | } |
jwalker366 | 3:2499b6bda80f | 283 | |
jwalker366 | 3:2499b6bda80f | 284 | for (int i=0; 5 ;++i) |
jwalker366 | 3:2499b6bda80f | 285 | { //tbis part prints the dice on the ulcd |
jwalker366 | 3:2499b6bda80f | 286 | |
jwalker366 | 3:2499b6bda80f | 287 | if(selectedDiceArray[i] == false) |
jwalker366 | 3:2499b6bda80f | 288 | {//this wont reprint the values of the duce if the dice has been selected on the bluetooth |
jwalker366 | 3:2499b6bda80f | 289 | diceLoc(i,randoArray[i],1);// print function for dice. i is the location of the dice and rando is a random number for the dice face |
jwalker366 | 3:2499b6bda80f | 290 | } |
jwalker366 | 3:2499b6bda80f | 291 | else if (selectedDiceArray[i] == true) |
jwalker366 | 3:2499b6bda80f | 292 | { |
jwalker366 | 3:2499b6bda80f | 293 | diceLoc(i,randoArray[i],2); |
jwalker366 | 3:2499b6bda80f | 294 | //faceValCarry[i] = randoArray[i];// I think this works, what I am tring to do is retain the random value I generated earlier |
jwalker366 | 3:2499b6bda80f | 295 | } |
jwalker366 | 3:2499b6bda80f | 296 | } |
jwalker366 | 3:2499b6bda80f | 297 | |
jwalker366 | 3:2499b6bda80f | 298 | draw_diceDisp(); |
jwalker366 | 3:2499b6bda80f | 299 | wait(2); |
jwalker366 | 3:2499b6bda80f | 300 | |
jwalker366 | 3:2499b6bda80f | 301 | while(1) |
jwalker366 | 3:2499b6bda80f | 302 | { |
jwalker366 | 3:2499b6bda80f | 303 | draw_diceSelect(); |
jwalker366 | 3:2499b6bda80f | 304 | but_pushed1 = pb1; |
jwalker366 | 3:2499b6bda80f | 305 | but_pushed2 = pb2; |
jwalker366 | 3:2499b6bda80f | 306 | if(but_pushed1==1) |
jwalker366 | 3:2499b6bda80f | 307 | { |
jwalker366 | 3:2499b6bda80f | 308 | selectDice(); |
jwalker366 | 3:2499b6bda80f | 309 | break; |
jwalker366 | 3:2499b6bda80f | 310 | } |
jwalker366 | 3:2499b6bda80f | 311 | |
jwalker366 | 3:2499b6bda80f | 312 | else if(but_pushed2==1) |
jwalker366 | 3:2499b6bda80f | 313 | { |
jwalker366 | 3:2499b6bda80f | 314 | break; |
jwalker366 | 3:2499b6bda80f | 315 | } |
jwalker366 | 3:2499b6bda80f | 316 | } |
jwalker366 | 3:2499b6bda80f | 317 | } |
jwalker366 | 3:2499b6bda80f | 318 | |
jwalker366 | 3:2499b6bda80f | 319 | while (1) |
jwalker366 | 3:2499b6bda80f | 320 | {//score screen |
jwalker366 | 3:2499b6bda80f | 321 | draw_scoreScreen(); |
jwalker366 | 3:2499b6bda80f | 322 | } |
jwalker366 | 3:2499b6bda80f | 323 | |
jwalker366 | 3:2499b6bda80f | 324 | |
jwalker366 | 3:2499b6bda80f | 325 | }//end main() |
jwalker366 | 3:2499b6bda80f | 326 | |
jwalker366 | 3:2499b6bda80f | 327 | |
jwalker366 | 3:2499b6bda80f | 328 | //selectedDice = selectDice(); |
jwalker366 | 3:2499b6bda80f | 329 | //pc.printf("Selected Dice: '%d %d'\n", selectedDice, selectedDiceArray[selectedDice]); |
ridwangs7 | 1:f264a7ecd285 | 330 | |
ridwangs7 | 1:f264a7ecd285 | 331 | /* pseudocode to match flow block diagram |
ridwangs7 | 1:f264a7ecd285 | 332 | but_pushed = -1; |
ridwangs7 | 1:f264a7ecd285 | 333 | while(but_pushed != 2){ // enter while if 1 pressed (yes) -> (initially -1) |
ridwangs7 | 1:f264a7ecd285 | 334 | but_pushed = -1; |
ridwangs7 | 1:f264a7ecd285 | 335 | while (but_pushed != 1){ |
ridwangs7 | 1:f264a7ecd285 | 336 | draw_readyRoll(); |
ridwangs7 | 1:f264a7ecd285 | 337 | draw_diceDisp(); |
ridwangs7 | 1:f264a7ecd285 | 338 | } |
ridwangs7 | 1:f264a7ecd285 | 339 | draw_diceSelect(); |
ridwangs7 | 1:f264a7ecd285 | 340 | } |
ridwangs7 | 1:f264a7ecd285 | 341 | */ |
ridwangs7 | 1:f264a7ecd285 | 342 | // draw_scoreScreen(); |
jwalker366 | 3:2499b6bda80f | 343 |