Bluetooth
Dependencies: 4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player
Diff: main.cpp
- Revision:
- 2:655c8a5c2ad8
- Parent:
- 1:f264a7ecd285
- Child:
- 3:2499b6bda80f
diff -r f264a7ecd285 -r 655c8a5c2ad8 main.cpp --- a/main.cpp Fri Dec 02 17:46:34 2022 +0000 +++ b/main.cpp Sat Dec 03 17:30:14 2022 +0000 @@ -4,10 +4,12 @@ Emanuel Abdul-Salaam Juan Padilla */ - +#include <time.h> /* time_t, struct tm, difftime, time, mktime */ +#include <ctime> #include "mbed.h" #include "uLCD_4DGL.h" +MMA8452 acc(p28, p27, 40000); //instantiate an acc object BusOut myled(LED1,LED2,LED3,LED4); Serial blue(p9,p10); Serial pc(USBTX, USBRX); @@ -16,6 +18,7 @@ int but_pushed = -1; // ==1 -> pb1 pushed, == 2 -> pb2 pushed bool selectedDiceArray[5]; +int accFlag = 1; // this is gonna be the variable that the accelerometer flips to roll the dice int selectDice() @@ -115,6 +118,92 @@ } +// This fuctuion prints a single dice to the screen, but can be used over and over to print every dice + int xarry[] = {22,22,64,64,105};//holds the center point for every dice on the X axis (for uLCD) + int yarry[] = {32,96,32,96,32};//holds the center point for every dice on the Y axis (for uLCD) +void diceLoc(int diceLoc,int diceFaceNum)//diceLoc is the location of the dice (1-5) and diceFaceNum is the number on the dice face (provided by a random number gen +{ + + int x1=xarry[diceLoc] + 20; + int x2=xarry[diceLoc] - 20; + int y1=yarry[diceLoc] + 20; + int y2=yarry[diceLoc] - 20; + uLCD.rectangle(x1,y1,x2,y2,WHITE); + switch(diceFaceNum){ + case 1://if dice =1 + uLCD.filled_circle(xarry[diceLoc] , yarry[diceLoc] ,3, WHITE); + num1++; + break; + + case 2://if dice =2 + + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10), 3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); + num2++; + + break; + + case 3://so on + uLCD.filled_circle((xarry[diceLoc]) , (yarry[diceLoc]) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc] - 10) ,3, WHITE); + num3++; + + break; + + case 4://so forth + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+ 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); + num4++; + + break; + + case 5: + + uLCD.filled_circle((xarry[diceLoc]) , (yarry[diceLoc]) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+ 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); + num5++; + break; + case 6: + + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]- 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]+10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]+ 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10) , (yarry[diceLoc]- 10) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]+ 10) , (yarry[diceLoc]) ,3, WHITE); + uLCD.filled_circle((xarry[diceLoc]- 10 ) , (yarry[diceLoc]) ,3, WHITE); + num6++; + break; + + default: + break; + } +//end dice printing function + + + int shakeDetect(int accFlag){ + acc.setBitDepth(MMA8452::BIT_DEPTH_12); + acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); + acc.setDataRate(MMA8452::RATE_100);// dont worry about this garbage. it just sets some internal values for the acc + + double x = 0; + while(1){ + acc.readXGravity(&x); //notice this is passed by reference use pointers + + if(x >= .6){ + accFlag = 0; + break; + } + } + return accFlag;// this is to pass back the value of the acc flag so I dont do an extra run. +} +// end acc stuff + int main() { ulcd.cls();