Power Grid Board Game Timer. Acts like a chess timer for 3-6 people. Uses an ADXL accelerometer to pause the timer and change players. Uses an LCD screen to prompt the players for input, read that input, and change between rounds.

Dependencies:   DmTouch_UniGraphic UniGraphic-forLdelaney17FinalProject mbed

Committer:
ldelaney17
Date:
Wed Jan 25 16:30:13 2017 +0000
Revision:
5:e07903df9510
Parent:
2:e6788e73de54
publish commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ldelaney17 0:1abea3982908 1 #include "acc.h"
ldelaney17 2:e6788e73de54 2
ldelaney17 0:1abea3982908 3
ldelaney17 0:1abea3982908 4 void acc_init(float duration, float threshold, float gap, float window){
ldelaney17 0:1abea3982908 5 //acc = &connection;
ldelaney17 0:1abea3982908 6 char durationByte, thresholdByte, gapByte, windowByte;
ldelaney17 0:1abea3982908 7
ldelaney17 0:1abea3982908 8 //convert the function parameters from their respective units to the appropriate byte values
ldelaney17 0:1abea3982908 9 durationByte = duration / 0.625;
ldelaney17 0:1abea3982908 10 thresholdByte = threshold / 0.00625;
ldelaney17 0:1abea3982908 11 gapByte = gap / 1.25;
ldelaney17 0:1abea3982908 12 windowByte = window / 1.25;
ldelaney17 0:1abea3982908 13
ldelaney17 0:1abea3982908 14 //set the config constants
ldelaney17 0:1abea3982908 15 char acc_config_dataFormat[2] = {0x31,0x0b}; //measurement range
ldelaney17 0:1abea3982908 16 char acc_config_powerControl[2] = {0x2d,0x08};
ldelaney17 0:1abea3982908 17 char acc_config_tapThreshold[2] = {0x1d,thresholdByte};
ldelaney17 0:1abea3982908 18 char acc_config_tapDuration[2] = {0x21,durationByte};
ldelaney17 0:1abea3982908 19 char acc_config_latentGap[2] = {0x22,gapByte};
ldelaney17 0:1abea3982908 20 char acc_config_window[2] = {0x23,windowByte};
ldelaney17 0:1abea3982908 21 char acc_config_enableAxis[2] = {0x2a,0x07};
ldelaney17 0:1abea3982908 22 char acc_config_intEnable[2] = {0x2e,0x60};
ldelaney17 0:1abea3982908 23 char acc_config_intMap[2] = {0x2f,0x60};
ldelaney17 0:1abea3982908 24
ldelaney17 0:1abea3982908 25 //set the configuration
ldelaney17 0:1abea3982908 26 connection.write(addr_acc, acc_config_dataFormat, 2); //full measurement range
ldelaney17 0:1abea3982908 27 wait(.05);
ldelaney17 0:1abea3982908 28 connection.write(addr_acc, acc_config_tapDuration, 2);
ldelaney17 0:1abea3982908 29 wait(.05);
ldelaney17 0:1abea3982908 30 connection.write(addr_acc, acc_config_tapThreshold, 2);
ldelaney17 0:1abea3982908 31 wait(.05);
ldelaney17 0:1abea3982908 32 connection.write(addr_acc, acc_config_latentGap, 2);
ldelaney17 0:1abea3982908 33 wait(.05);
ldelaney17 0:1abea3982908 34 connection.write(addr_acc, acc_config_window, 2);
ldelaney17 0:1abea3982908 35 wait(.05);
ldelaney17 0:1abea3982908 36 connection.write(addr_acc, acc_config_enableAxis, 2);
ldelaney17 0:1abea3982908 37 wait(.05);
ldelaney17 0:1abea3982908 38 connection.write(addr_acc, acc_config_intEnable, 2);
ldelaney17 0:1abea3982908 39 wait(.05);
ldelaney17 0:1abea3982908 40 connection.write(addr_acc, acc_config_intMap, 2);
ldelaney17 0:1abea3982908 41 wait(.05);
ldelaney17 0:1abea3982908 42 connection.write(addr_acc, acc_config_powerControl, 2); // measure mode
ldelaney17 0:1abea3982908 43 wait(.05);
ldelaney17 0:1abea3982908 44 }
ldelaney17 0:1abea3982908 45
ldelaney17 0:1abea3982908 46 char get_int_type(){
ldelaney17 0:1abea3982908 47 char int_source_arr[2] = {0x30|0x80, 0x00};
ldelaney17 0:1abea3982908 48 connection.write(addr_acc, int_source_arr, 1); //set up the connection for reading from int_source
ldelaney17 0:1abea3982908 49 char acc_data[1];
ldelaney17 0:1abea3982908 50 connection.read(addr_acc, acc_data, 1); //read the int_source byte
ldelaney17 0:1abea3982908 51 //pc.printf("%x\t",acc_data[0]&0x60); //this was used for debugging
ldelaney17 0:1abea3982908 52 if(acc_data[0] & 0x20) //if a double tap, return 2
ldelaney17 0:1abea3982908 53 return 2;
ldelaney17 0:1abea3982908 54 else if (acc_data[0] & 0x40) //if a single tap, return 1
ldelaney17 0:1abea3982908 55 return 1;
ldelaney17 0:1abea3982908 56 //this code should never be reached, but is included so that there is an appropriate exit path
ldelaney17 0:1abea3982908 57 return 0;
ldelaney17 0:1abea3982908 58 }