Revised code. The original has been removed.

Dependencies:   USBDevice mbed

Committer:
willgeorge
Date:
Tue Feb 03 22:11:06 2015 +0000
Revision:
0:305fa754c01e
Updated code. I have removed the original code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
willgeorge 0:305fa754c01e 1
willgeorge 0:305fa754c01e 2
willgeorge 0:305fa754c01e 3 //I have removed Library LCD_ST7735 that was in the original post.
willgeorge 0:305fa754c01e 4 //Chris Taylor (taylorza) has reminded me that I was not using his library as I had stated.
willgeorge 0:305fa754c01e 5
willgeorge 0:305fa754c01e 6 //I know nothing about payouts on a 'real' slot machine so I just made some up...
willgeorge 0:305fa754c01e 7 //Be creative and make your own!
willgeorge 0:305fa754c01e 8
willgeorge 0:305fa754c01e 9 //There is no calculated payback percentage (Odds).
willgeorge 0:305fa754c01e 10 //Fruits displayed and payout values for two of a kind are chosen by random numbers.
willgeorge 0:305fa754c01e 11 //LUCKY7 - All payouts are fixed values
willgeorge 0:305fa754c01e 12
willgeorge 0:305fa754c01e 13
willgeorge 0:305fa754c01e 14 #include "mbed.h"
willgeorge 0:305fa754c01e 15 #include <stdarg.h>
willgeorge 0:305fa754c01e 16 #include <stdlib.h>
willgeorge 0:305fa754c01e 17 #include "USBSerial.h"
willgeorge 0:305fa754c01e 18 #include <string>
willgeorge 0:305fa754c01e 19
willgeorge 0:305fa754c01e 20 #include "DisplayN18.h"
willgeorge 0:305fa754c01e 21
willgeorge 0:305fa754c01e 22 bool spin = false;
willgeorge 0:305fa754c01e 23
willgeorge 0:305fa754c01e 24 AnalogIn ain(P0_15); //One of the user header pins
willgeorge 0:305fa754c01e 25
willgeorge 0:305fa754c01e 26 DigitalOut led1(P0_9, 0);
willgeorge 0:305fa754c01e 27 DigitalOut led2(P0_8, 1);
willgeorge 0:305fa754c01e 28 DigitalOut Buzzer(P0_18);
willgeorge 0:305fa754c01e 29
willgeorge 0:305fa754c01e 30 DigitalIn up(P0_13, PullUp);
willgeorge 0:305fa754c01e 31 DigitalIn down(P0_12, PullUp);
willgeorge 0:305fa754c01e 32 DigitalIn left(P0_14, PullUp);
willgeorge 0:305fa754c01e 33 DigitalIn right(P0_11, PullUp);
willgeorge 0:305fa754c01e 34
willgeorge 0:305fa754c01e 35 DigitalIn pbRobot(P0_16, PullUp);
willgeorge 0:305fa754c01e 36
willgeorge 0:305fa754c01e 37 //Falling edge (hit) generates an interrupt
willgeorge 0:305fa754c01e 38 //Just wanted to try an interrupt
willgeorge 0:305fa754c01e 39 InterruptIn pbSpaceship(P0_1);
willgeorge 0:305fa754c01e 40
willgeorge 0:305fa754c01e 41 //Random numbers for reels()
willgeorge 0:305fa754c01e 42 int r1 = 0;
willgeorge 0:305fa754c01e 43 int r2 = 0;
willgeorge 0:305fa754c01e 44 int r3 = 0;
willgeorge 0:305fa754c01e 45 int r4 = 0;
willgeorge 0:305fa754c01e 46 int r5 = 0;
willgeorge 0:305fa754c01e 47 int r6 = 0;
willgeorge 0:305fa754c01e 48
willgeorge 0:305fa754c01e 49 //Virtual serial port over USB.
willgeorge 0:305fa754c01e 50 //Used for debug output only
willgeorge 0:305fa754c01e 51 USBSerial serial;
willgeorge 0:305fa754c01e 52
willgeorge 0:305fa754c01e 53 DisplayN18 disp;
willgeorge 0:305fa754c01e 54
willgeorge 0:305fa754c01e 55 bool doublepay = false;
willgeorge 0:305fa754c01e 56 bool win = false;
willgeorge 0:305fa754c01e 57
willgeorge 0:305fa754c01e 58 int cash = 100; //Start with
willgeorge 0:305fa754c01e 59 int cashpay = 0; //Win or loss
willgeorge 0:305fa754c01e 60
willgeorge 0:305fa754c01e 61 const char * const bar[] = {
willgeorge 0:305fa754c01e 62 "BAR ",
willgeorge 0:305fa754c01e 63 "BELL ",
willgeorge 0:305fa754c01e 64 "ORANGE ",
willgeorge 0:305fa754c01e 65 "LEMON ",
willgeorge 0:305fa754c01e 66 "LUCKY7 ",
willgeorge 0:305fa754c01e 67 "CHERRY " };
willgeorge 0:305fa754c01e 68
willgeorge 0:305fa754c01e 69 const char* msg1 = "";
willgeorge 0:305fa754c01e 70 const char* msg2 = "";
willgeorge 0:305fa754c01e 71 const char* msg3 = "";
willgeorge 0:305fa754c01e 72
willgeorge 0:305fa754c01e 73 //Screen width using spaces
willgeorge 0:305fa754c01e 74 const char* szErase = " "; //26 spaces
willgeorge 0:305fa754c01e 75
willgeorge 0:305fa754c01e 76 //From E-Dice
willgeorge 0:305fa754c01e 77 void soundBuzzer(int Hz)
willgeorge 0:305fa754c01e 78 {
willgeorge 0:305fa754c01e 79 int ticks = Hz/64;
willgeorge 0:305fa754c01e 80 int tickCount = 0;
willgeorge 0:305fa754c01e 81 float frequency = 1/(float)Hz;
willgeorge 0:305fa754c01e 82
willgeorge 0:305fa754c01e 83 while(tickCount < ticks)
willgeorge 0:305fa754c01e 84 {
willgeorge 0:305fa754c01e 85 wait(frequency);
willgeorge 0:305fa754c01e 86 Buzzer = true;
willgeorge 0:305fa754c01e 87 wait(frequency);
willgeorge 0:305fa754c01e 88 Buzzer = false;
willgeorge 0:305fa754c01e 89 tickCount++;
willgeorge 0:305fa754c01e 90 }
willgeorge 0:305fa754c01e 91 }
willgeorge 0:305fa754c01e 92 //
willgeorge 0:305fa754c01e 93
willgeorge 0:305fa754c01e 94 void reels(void)
willgeorge 0:305fa754c01e 95 {
willgeorge 0:305fa754c01e 96 //Erase current text (-val = position from bottom of LCD)
willgeorge 0:305fa754c01e 97 //Fruit bars
willgeorge 0:305fa754c01e 98 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -58, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 99
willgeorge 0:305fa754c01e 100 //Erase current text
willgeorge 0:305fa754c01e 101 //DOUBLE PAY (May not be used but we will erase that position anyway)
willgeorge 0:305fa754c01e 102 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT + 73, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 103
willgeorge 0:305fa754c01e 104 while(spin) {
willgeorge 0:305fa754c01e 105
willgeorge 0:305fa754c01e 106 r1 = (rand() % 6); //Fruit 1
willgeorge 0:305fa754c01e 107 r2 = (rand() % 6); //Fruit 2
willgeorge 0:305fa754c01e 108 r3 = (rand() % 6); //Fruit 3
willgeorge 0:305fa754c01e 109 r4 = (rand() % 50); //Double Pay if 34,13,7
willgeorge 0:305fa754c01e 110 r5 = (rand() % 2); //LOSE! 1 or 2 dollars
willgeorge 0:305fa754c01e 111 r6 = (rand() % 4) +1; //cashpay on two of a kind. (+1 for no zero wanted)
willgeorge 0:305fa754c01e 112
willgeorge 0:305fa754c01e 113 //Use if wanted to show the random number values
willgeorge 0:305fa754c01e 114 serial.printf(" %d %d %d %d %d %d\r\n",r1,r2,r3,r4,r5,r6);
willgeorge 0:305fa754c01e 115
willgeorge 0:305fa754c01e 116 msg1 = bar[r1];
willgeorge 0:305fa754c01e 117 msg2 = bar[r2];
willgeorge 0:305fa754c01e 118 msg3 = bar[r3];
willgeorge 0:305fa754c01e 119
willgeorge 0:305fa754c01e 120 char buf[27] = "";
willgeorge 0:305fa754c01e 121 strncat(buf, msg1, sizeof buf);
willgeorge 0:305fa754c01e 122 strncat(buf, msg2, sizeof buf - strlen(buf));
willgeorge 0:305fa754c01e 123 strncat(buf, msg3, sizeof buf - strlen(buf));
willgeorge 0:305fa754c01e 124
willgeorge 0:305fa754c01e 125 //Erase current text then draw new text centered
willgeorge 0:305fa754c01e 126 //Fruit bars
willgeorge 0:305fa754c01e 127 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -58, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 128 disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) *
willgeorge 0:305fa754c01e 129 strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT - 58, buf, DisplayN18::GREEN, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 130
willgeorge 0:305fa754c01e 131 //Robot button is Not pressed
willgeorge 0:305fa754c01e 132 if(pbRobot) {
willgeorge 0:305fa754c01e 133 //YOUR PLAY
willgeorge 0:305fa754c01e 134 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -78, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 135 }
willgeorge 0:305fa754c01e 136 //
willgeorge 0:305fa754c01e 137 wait(0.1);
willgeorge 0:305fa754c01e 138
willgeorge 0:305fa754c01e 139 //Robot button was pressed
willgeorge 0:305fa754c01e 140 if(!pbRobot) {
willgeorge 0:305fa754c01e 141 led2 = 1;
willgeorge 0:305fa754c01e 142 led1 = 0;
willgeorge 0:305fa754c01e 143
willgeorge 0:305fa754c01e 144 char buf[27] = "";
willgeorge 0:305fa754c01e 145 sprintf(buf, "YOUR PLAY - Cash %d ", cash);
willgeorge 0:305fa754c01e 146
willgeorge 0:305fa754c01e 147 //Erase current text then draw new text centered
willgeorge 0:305fa754c01e 148 //YOUR PLAY
willgeorge 0:305fa754c01e 149 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -78, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 150 disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) *
willgeorge 0:305fa754c01e 151 strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT - 78, buf, DisplayN18::GREEN, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 152
willgeorge 0:305fa754c01e 153 //Erase current text
willgeorge 0:305fa754c01e 154 //WIN/LOSS Cash at hand
willgeorge 0:305fa754c01e 155 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -16, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 156
willgeorge 0:305fa754c01e 157 spin = false;
willgeorge 0:305fa754c01e 158
willgeorge 0:305fa754c01e 159 //Show fruit bars left to right one at a time
willgeorge 0:305fa754c01e 160 //1 second interval
willgeorge 0:305fa754c01e 161 for(int i =0; i <= 2; i++)
willgeorge 0:305fa754c01e 162 {
willgeorge 0:305fa754c01e 163 msg1 = bar[r1];
willgeorge 0:305fa754c01e 164 msg2 = bar[r2];
willgeorge 0:305fa754c01e 165 msg3 = bar[r3];
willgeorge 0:305fa754c01e 166 char buf[27] = "";
willgeorge 0:305fa754c01e 167
willgeorge 0:305fa754c01e 168 if(i == 0) {
willgeorge 0:305fa754c01e 169 strncat(buf, msg1, sizeof buf);
willgeorge 0:305fa754c01e 170 }
willgeorge 0:305fa754c01e 171 if(i == 1) {
willgeorge 0:305fa754c01e 172 strncat(buf, msg1, sizeof buf);
willgeorge 0:305fa754c01e 173 strncat(buf, msg2, sizeof buf - strlen(buf));
willgeorge 0:305fa754c01e 174 }
willgeorge 0:305fa754c01e 175 if(i == 2) {
willgeorge 0:305fa754c01e 176 strncat(buf, msg1, sizeof buf);
willgeorge 0:305fa754c01e 177 strncat(buf, msg2, sizeof buf - strlen(buf));
willgeorge 0:305fa754c01e 178 strncat(buf, msg3, sizeof buf - strlen(buf));
willgeorge 0:305fa754c01e 179 }
willgeorge 0:305fa754c01e 180
willgeorge 0:305fa754c01e 181 //Erase current text then draw new text centered
willgeorge 0:305fa754c01e 182 //Fruit bars
willgeorge 0:305fa754c01e 183 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -58, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 184 disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) *
willgeorge 0:305fa754c01e 185 strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT - 58, buf, DisplayN18::RED, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 186
willgeorge 0:305fa754c01e 187 wait(1);
willgeorge 0:305fa754c01e 188
willgeorge 0:305fa754c01e 189 //Erase current text then draw new text centered
willgeorge 0:305fa754c01e 190 //Fruit bars
willgeorge 0:305fa754c01e 191 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -58, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 192 disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) *
willgeorge 0:305fa754c01e 193 strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT - 58, buf, DisplayN18::GREEN, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 194 } //for
willgeorge 0:305fa754c01e 195
willgeorge 0:305fa754c01e 196 win = false;
willgeorge 0:305fa754c01e 197
willgeorge 0:305fa754c01e 198 //bar[2] = ORANGE
willgeorge 0:305fa754c01e 199 if ((msg1 == bar[2]) && (msg2 == bar[2]) && (msg3 == bar[2]))
willgeorge 0:305fa754c01e 200 {
willgeorge 0:305fa754c01e 201 cash = cash + 4;
willgeorge 0:305fa754c01e 202 cashpay = 4;
willgeorge 0:305fa754c01e 203 win = true;
willgeorge 0:305fa754c01e 204 }
willgeorge 0:305fa754c01e 205 if ((msg1 == bar[2]) && (msg2 == bar[2]))
willgeorge 0:305fa754c01e 206 {
willgeorge 0:305fa754c01e 207 cash = cash + r6;
willgeorge 0:305fa754c01e 208 cashpay = r6;
willgeorge 0:305fa754c01e 209 win = true;
willgeorge 0:305fa754c01e 210 }
willgeorge 0:305fa754c01e 211 if ((msg2 == bar[2]) && (msg3 == bar[2]))
willgeorge 0:305fa754c01e 212 {
willgeorge 0:305fa754c01e 213 cash = cash + r6;
willgeorge 0:305fa754c01e 214 cashpay = r6;
willgeorge 0:305fa754c01e 215 win = true;
willgeorge 0:305fa754c01e 216 }
willgeorge 0:305fa754c01e 217 //
willgeorge 0:305fa754c01e 218
willgeorge 0:305fa754c01e 219 //bar[3] = LEMON
willgeorge 0:305fa754c01e 220 if ((msg1 == bar[3]) && (msg2 == bar[3]) && (msg3 == bar[3]))
willgeorge 0:305fa754c01e 221 {
willgeorge 0:305fa754c01e 222 cash = cash + 4;
willgeorge 0:305fa754c01e 223 cashpay = 4;
willgeorge 0:305fa754c01e 224 win = true;
willgeorge 0:305fa754c01e 225 }
willgeorge 0:305fa754c01e 226 if ((msg1 == bar[3]) && (msg2 == bar[3]))
willgeorge 0:305fa754c01e 227 {
willgeorge 0:305fa754c01e 228 cash = cash + r6;
willgeorge 0:305fa754c01e 229 cashpay = r6;
willgeorge 0:305fa754c01e 230 win = true;
willgeorge 0:305fa754c01e 231 }
willgeorge 0:305fa754c01e 232 if ((msg2 == bar[3]) && (msg3 == bar[3]))
willgeorge 0:305fa754c01e 233 {
willgeorge 0:305fa754c01e 234 cash = cash + r6;
willgeorge 0:305fa754c01e 235 cashpay = r6;
willgeorge 0:305fa754c01e 236 win = true;
willgeorge 0:305fa754c01e 237 }
willgeorge 0:305fa754c01e 238 //
willgeorge 0:305fa754c01e 239
willgeorge 0:305fa754c01e 240 //bar[5] = CHERRY
willgeorge 0:305fa754c01e 241 if ((msg1 == bar[5]) && (msg2 == bar[5]) && (msg3 == bar[5]))
willgeorge 0:305fa754c01e 242 {
willgeorge 0:305fa754c01e 243 cash = cash + 6;
willgeorge 0:305fa754c01e 244 cashpay = 6;
willgeorge 0:305fa754c01e 245 win = true;
willgeorge 0:305fa754c01e 246 }
willgeorge 0:305fa754c01e 247 if ((msg1 == bar[5]) && (msg2 == bar[5]))
willgeorge 0:305fa754c01e 248 {
willgeorge 0:305fa754c01e 249 cash = cash + r6;
willgeorge 0:305fa754c01e 250 cashpay = r6;
willgeorge 0:305fa754c01e 251 win = true;
willgeorge 0:305fa754c01e 252 }
willgeorge 0:305fa754c01e 253 if ((msg2 == bar[5]) && (msg3 == bar[5]))
willgeorge 0:305fa754c01e 254 {
willgeorge 0:305fa754c01e 255 cash = cash + r6;
willgeorge 0:305fa754c01e 256 cashpay = r6;
willgeorge 0:305fa754c01e 257 win = true;
willgeorge 0:305fa754c01e 258 }
willgeorge 0:305fa754c01e 259 //
willgeorge 0:305fa754c01e 260
willgeorge 0:305fa754c01e 261 //bar[1] = BELL
willgeorge 0:305fa754c01e 262 if ((msg1 == bar[1]) && (msg2 == bar[1]) && (msg3 == bar[1]))
willgeorge 0:305fa754c01e 263 {
willgeorge 0:305fa754c01e 264 cash = cash + 6;
willgeorge 0:305fa754c01e 265 cashpay = 6;
willgeorge 0:305fa754c01e 266 win = true;
willgeorge 0:305fa754c01e 267 }
willgeorge 0:305fa754c01e 268 if ((msg1 == bar[1]) && (msg2 == bar[1]))
willgeorge 0:305fa754c01e 269 {
willgeorge 0:305fa754c01e 270 cash = cash + r6;
willgeorge 0:305fa754c01e 271 cashpay = r6;
willgeorge 0:305fa754c01e 272 win = true;
willgeorge 0:305fa754c01e 273 }
willgeorge 0:305fa754c01e 274 if ((msg2 == bar[1]) && (msg3 == bar[1]))
willgeorge 0:305fa754c01e 275 {
willgeorge 0:305fa754c01e 276 cash = cash + r6;
willgeorge 0:305fa754c01e 277 cashpay = r6;
willgeorge 0:305fa754c01e 278 win = true;
willgeorge 0:305fa754c01e 279 }
willgeorge 0:305fa754c01e 280 //
willgeorge 0:305fa754c01e 281
willgeorge 0:305fa754c01e 282 //bar[0] = BAR
willgeorge 0:305fa754c01e 283 if ((msg1 == bar[0]) && (msg2 == bar[0]) && (msg3 == bar[0]))
willgeorge 0:305fa754c01e 284 {
willgeorge 0:305fa754c01e 285 cash = cash + 10;
willgeorge 0:305fa754c01e 286 cashpay = 10;
willgeorge 0:305fa754c01e 287 win = true;
willgeorge 0:305fa754c01e 288 }
willgeorge 0:305fa754c01e 289 if ((msg1 == bar[0]) && (msg2 == bar[0]))
willgeorge 0:305fa754c01e 290 {
willgeorge 0:305fa754c01e 291 cash = cash + r6;
willgeorge 0:305fa754c01e 292 cashpay = r6;
willgeorge 0:305fa754c01e 293 win = true;
willgeorge 0:305fa754c01e 294 }
willgeorge 0:305fa754c01e 295 if ((msg2 == bar[0]) && (msg3 == bar[0]))
willgeorge 0:305fa754c01e 296 {
willgeorge 0:305fa754c01e 297 cash = cash + r6;
willgeorge 0:305fa754c01e 298 cashpay = r6;
willgeorge 0:305fa754c01e 299 win = true;
willgeorge 0:305fa754c01e 300 }
willgeorge 0:305fa754c01e 301 //
willgeorge 0:305fa754c01e 302
willgeorge 0:305fa754c01e 303 //bar[4] = LUCKY7
willgeorge 0:305fa754c01e 304 if ((msg1 == bar[4]) && (msg2 == bar[4]) && (msg3 == bar[4]))
willgeorge 0:305fa754c01e 305 {
willgeorge 0:305fa754c01e 306 cash = cash + 20;
willgeorge 0:305fa754c01e 307 cashpay = 20;
willgeorge 0:305fa754c01e 308 win = true;
willgeorge 0:305fa754c01e 309 }
willgeorge 0:305fa754c01e 310 if ((msg1 == bar[4]) && (msg2 == bar[4]))
willgeorge 0:305fa754c01e 311 {
willgeorge 0:305fa754c01e 312 cash = cash + 10;
willgeorge 0:305fa754c01e 313 cashpay = 10;
willgeorge 0:305fa754c01e 314 win = true;
willgeorge 0:305fa754c01e 315 }
willgeorge 0:305fa754c01e 316 if ((msg2 == bar[4]) && (msg3 == bar[4]))
willgeorge 0:305fa754c01e 317 {
willgeorge 0:305fa754c01e 318 cash = cash + 8;
willgeorge 0:305fa754c01e 319 cashpay = 8;
willgeorge 0:305fa754c01e 320 win = true;
willgeorge 0:305fa754c01e 321 }
willgeorge 0:305fa754c01e 322 //
willgeorge 0:305fa754c01e 323
willgeorge 0:305fa754c01e 324 if(win)
willgeorge 0:305fa754c01e 325 {
willgeorge 0:305fa754c01e 326 if(r4 == 35 || r4 == 13 || r4 == 7) {
willgeorge 0:305fa754c01e 327 sprintf(buf, "DOUBLE PAY %d %d ", cashpay * 2, cash + cashpay);
willgeorge 0:305fa754c01e 328 }
willgeorge 0:305fa754c01e 329 else {
willgeorge 0:305fa754c01e 330 sprintf(buf, "WIN! Pay: %d Cash: %d ", cashpay, cash);
willgeorge 0:305fa754c01e 331 }
willgeorge 0:305fa754c01e 332 }
willgeorge 0:305fa754c01e 333 //
willgeorge 0:305fa754c01e 334
willgeorge 0:305fa754c01e 335 if(!win)
willgeorge 0:305fa754c01e 336 {
willgeorge 0:305fa754c01e 337 if(r5 == 0) {
willgeorge 0:305fa754c01e 338 cash = cash - 1;
willgeorge 0:305fa754c01e 339 sprintf(buf, "LOSE! 1 dollar - %d ", cash);
willgeorge 0:305fa754c01e 340 }
willgeorge 0:305fa754c01e 341 else if(r5 == 1) {
willgeorge 0:305fa754c01e 342 cash = cash - 2;
willgeorge 0:305fa754c01e 343 sprintf(buf, "LOSE! 2 dollars - %d ", cash);
willgeorge 0:305fa754c01e 344 }
willgeorge 0:305fa754c01e 345
willgeorge 0:305fa754c01e 346 }
willgeorge 0:305fa754c01e 347 //
willgeorge 0:305fa754c01e 348
willgeorge 0:305fa754c01e 349 //Erase current text then draw new text centered
willgeorge 0:305fa754c01e 350 //WIN/LOSS Cash at hand
willgeorge 0:305fa754c01e 351 disp.drawString(0, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT -16, szErase, DisplayN18::BLACK, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 352 disp.drawString(DisplayN18::WIDTH / 2 - (DisplayN18::CHAR_WIDTH + DisplayN18::CHAR_SPACING) *
willgeorge 0:305fa754c01e 353 strlen(buf) / 2, DisplayN18::HEIGHT-DisplayN18::CHAR_HEIGHT - 16, buf, DisplayN18::GREEN, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 354
willgeorge 0:305fa754c01e 355 if(win) {
willgeorge 0:305fa754c01e 356 for(int i = 0; i < 5; i++) {
willgeorge 0:305fa754c01e 357 soundBuzzer(800);
willgeorge 0:305fa754c01e 358 wait(.1);
willgeorge 0:305fa754c01e 359 soundBuzzer(600);
willgeorge 0:305fa754c01e 360 wait(.1);
willgeorge 0:305fa754c01e 361 soundBuzzer(400);
willgeorge 0:305fa754c01e 362 wait(.1);
willgeorge 0:305fa754c01e 363 }
willgeorge 0:305fa754c01e 364 }
willgeorge 0:305fa754c01e 365 } //if
willgeorge 0:305fa754c01e 366 } //while
willgeorge 0:305fa754c01e 367 }
willgeorge 0:305fa754c01e 368 //
willgeorge 0:305fa754c01e 369
willgeorge 0:305fa754c01e 370 //Spaceship/RETRO button begins random pick of fruit bars
willgeorge 0:305fa754c01e 371 void pbSpaceship_hit_interrupt (void) {
willgeorge 0:305fa754c01e 372 led1 = 1;
willgeorge 0:305fa754c01e 373 led2 = 0;
willgeorge 0:305fa754c01e 374
willgeorge 0:305fa754c01e 375 spin = true;
willgeorge 0:305fa754c01e 376 reels();
willgeorge 0:305fa754c01e 377 }
willgeorge 0:305fa754c01e 378 //
willgeorge 0:305fa754c01e 379
willgeorge 0:305fa754c01e 380 int main() {
willgeorge 0:305fa754c01e 381
willgeorge 0:305fa754c01e 382 //For read_u16() - See: http://developer.mbed.org/handbook/AnalogIn
willgeorge 0:305fa754c01e 383 srand(ain.read_u16());
willgeorge 0:305fa754c01e 384
willgeorge 0:305fa754c01e 385 led1 = 0;
willgeorge 0:305fa754c01e 386 led2 = 0;
willgeorge 0:305fa754c01e 387 pbRobot.mode(PullUp);
willgeorge 0:305fa754c01e 388 //Delay for initial pullup to take effect
willgeorge 0:305fa754c01e 389 wait(.01);
willgeorge 0:305fa754c01e 390
willgeorge 0:305fa754c01e 391 pbSpaceship.mode(PullUp);
willgeorge 0:305fa754c01e 392 //Delay for initial pullup to take effect
willgeorge 0:305fa754c01e 393 wait(.01);
willgeorge 0:305fa754c01e 394
willgeorge 0:305fa754c01e 395 //Attach address of interrupt handler routine for pushbutton
willgeorge 0:305fa754c01e 396 pbSpaceship.fall(&pbSpaceship_hit_interrupt);
willgeorge 0:305fa754c01e 397
willgeorge 0:305fa754c01e 398 disp.clear();
willgeorge 0:305fa754c01e 399 wait(.5);
willgeorge 0:305fa754c01e 400
willgeorge 0:305fa754c01e 401 //Splash
willgeorge 0:305fa754c01e 402 char buf[27] = "";
willgeorge 0:305fa754c01e 403 sprintf(buf," OUTRAGEOUS RETRO Slot");
willgeorge 0:305fa754c01e 404 disp.drawString(0, 0, buf, DisplayN18::GREEN, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 405 sprintf(buf,"Press RETRO to pull Lever");
willgeorge 0:305fa754c01e 406 disp.drawString(0, DisplayN18::CHAR_HEIGHT + 3, buf, DisplayN18::RED, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 407 sprintf(buf,"Press ROBOT Lever up");
willgeorge 0:305fa754c01e 408 disp.drawString(0, DisplayN18::CHAR_HEIGHT + 13, buf, DisplayN18::RED, DisplayN18::BLACK);
willgeorge 0:305fa754c01e 409
willgeorge 0:305fa754c01e 410 while (true) {
willgeorge 0:305fa754c01e 411 wait(.1);
willgeorge 0:305fa754c01e 412 } //while
willgeorge 0:305fa754c01e 413 }
willgeorge 0:305fa754c01e 414 //