Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE PinDetect mbed
main.cpp
00001 #include "mbed.h" 00002 #include <stdio.h> /* printf */ 00003 #include <time.h> /* time_t, struct tm, difftime, time, mktime */ 00004 #include <ctime> 00005 #include "farkel_class.h" 00006 #include "die.h" 00007 #include "Speaker.h" 00008 00009 Speaker mySpeaker(p24); 00010 00011 void playJingle() 00012 { 00013 float g5=783.99; 00014 float f5=698.46; 00015 float e5=659.25; 00016 float d5=587.33; 00017 float g4=392; 00018 mySpeaker.PlayNote(g5,.32,.1); 00019 mySpeaker.PlayNote(f5,.32/2,.1); 00020 mySpeaker.PlayNote(e5,.32/2,.1); 00021 mySpeaker.PlayNote(d5,.32/2,.1); 00022 mySpeaker.PlayNote(g4,.32,.1); 00023 00024 } 00025 00026 Serial pc(USBTX,USBRX); //not used in this program 00027 MMA8452 acc(p28, p27, 40000); //instantiate an acc object! 00028 00029 int shakeDetect(int flag){ 00030 acc.setBitDepth(MMA8452::BIT_DEPTH_12); 00031 acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); 00032 acc.setDataRate(MMA8452::RATE_100); 00033 00034 double x = 0; 00035 while(1){ 00036 acc.readXGravity(&x); //notice this is passed by reference use pointers 00037 00038 if(x >= .6){ 00039 flag = 0; 00040 break; 00041 } 00042 } 00043 return flag; 00044 } 00045 00046 00047 00048 int main() { 00049 00050 srand(time(0)); 00051 farkel player1(0); 00052 Dice utility(0); 00053 int flag2Play = 0; 00054 int diceNum = 6; 00055 int mainMenuFlag = 0; 00056 int gameScore = 0; 00057 int scorehold = 0; 00058 double grav = 0; 00059 00060 while(1) { 00061 while(mainMenuFlag == 0 || mainMenuFlag ==1){ 00062 flag2Play = 0; 00063 if (mainMenuFlag == 1){ 00064 diceNum = 6; 00065 gameScore = 0; 00066 mainMenuFlag = 0; 00067 scorehold = 0; 00068 } 00069 00070 if(mainMenuFlag == 0){ 00071 player1.mainMenu(diceNum); 00072 } 00073 00074 acc.readXGravity(&grav); 00075 00076 if(grav >.6){ 00077 mainMenuFlag = 2; 00078 playJingle(); 00079 00080 } 00081 diceNum = player1.diceNumInc(diceNum); 00082 //mainMenuFlag = shakeDetect(mainMenuFlag); 00083 if(mainMenuFlag == 2){ 00084 player1.clearSc(); 00085 } 00086 } 00087 //uLCD.printf("Entered Loop"); wait(1); 00088 if(flag2Play == 0){ 00089 for (int i=0;i<diceNum;++i){ 00090 int rando = player1.roll(); 00091 player1.dicePlacer(i,rando,gameScore); 00092 } 00093 00094 scorehold = player1.gameScoring(); 00095 00096 if(scorehold == 0){ 00097 gameScore = 0; 00098 player1.printfark(); 00099 } 00100 gameScore += scorehold; 00101 00102 flag2Play++; 00103 }f 00104 00105 if(flag2Play == 1 || scorehold == 0 ){ 00106 mainMenuFlag = player1.butDetect(gameScore); 00107 player1.clearSc(); 00108 } 00109 diceNum = player1.resetDie(diceNum,scorehold); 00110 00111 //mainMenuFlag = player1.back2MainMenu(); 00112 00113 //uLCD.printf("Finished a loop"); wait(1); 00114 00115 } 00116 }
Generated on Mon Nov 21 2022 18:54:43 by
1.7.2