![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Bluetooth
Dependencies: 4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player
main.cpp@1:f264a7ecd285, 21 months ago (annotated)
- Committer:
- ridwangs7
- Date:
- Fri Dec 02 17:46:34 2022 +0000
- Revision:
- 1:f264a7ecd285
- Parent:
- 0:088af403d779
- Child:
- 2:655c8a5c2ad8
init
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 | */ |
ridwangs7 | 1:f264a7ecd285 | 7 | |
jwalker366 | 0:088af403d779 | 8 | #include "mbed.h" |
ridwangs7 | 1:f264a7ecd285 | 9 | #include "uLCD_4DGL.h" |
ridwangs7 | 1:f264a7ecd285 | 10 | |
ridwangs7 | 1:f264a7ecd285 | 11 | BusOut myled(LED1,LED2,LED3,LED4); |
ridwangs7 | 1:f264a7ecd285 | 12 | Serial blue(p9,p10); |
ridwangs7 | 1:f264a7ecd285 | 13 | Serial pc(USBTX, USBRX); |
ridwangs7 | 1:f264a7ecd285 | 14 | uLCD_4DGL ulcd(p13,p14,p11); |
ridwangs7 | 1:f264a7ecd285 | 15 | |
ridwangs7 | 1:f264a7ecd285 | 16 | |
ridwangs7 | 1:f264a7ecd285 | 17 | int but_pushed = -1; // ==1 -> pb1 pushed, == 2 -> pb2 pushed |
ridwangs7 | 1:f264a7ecd285 | 18 | bool selectedDiceArray[5]; |
ridwangs7 | 1:f264a7ecd285 | 19 | |
jwalker366 | 0:088af403d779 | 20 | |
ridwangs7 | 1:f264a7ecd285 | 21 | int selectDice() |
ridwangs7 | 1:f264a7ecd285 | 22 | { |
ridwangs7 | 1:f264a7ecd285 | 23 | char bnum=0; |
ridwangs7 | 1:f264a7ecd285 | 24 | char bhit=0; |
ridwangs7 | 1:f264a7ecd285 | 25 | int diceNum = 0; |
ridwangs7 | 1:f264a7ecd285 | 26 | |
ridwangs7 | 1:f264a7ecd285 | 27 | if (blue.getc()=='!') { |
ridwangs7 | 1:f264a7ecd285 | 28 | if (blue.getc()=='B') { //button data packet |
ridwangs7 | 1:f264a7ecd285 | 29 | bnum = blue.getc(); //button number |
ridwangs7 | 1:f264a7ecd285 | 30 | bhit = blue.getc(); //1=hit, 0=release |
ridwangs7 | 1:f264a7ecd285 | 31 | if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? |
ridwangs7 | 1:f264a7ecd285 | 32 | if ((bnum>='1')&&(bnum<='5')){ //is a number button 1..4 |
ridwangs7 | 1:f264a7ecd285 | 33 | diceNum = bnum-48; |
ridwangs7 | 1:f264a7ecd285 | 34 | selectedDiceArray[diceNum]= 1; |
ridwangs7 | 1:f264a7ecd285 | 35 | if (bhit=='1') { |
ridwangs7 | 1:f264a7ecd285 | 36 | myled = bnum - '0'; |
ridwangs7 | 1:f264a7ecd285 | 37 | } else { |
ridwangs7 | 1:f264a7ecd285 | 38 | myled = '0'; |
ridwangs7 | 1:f264a7ecd285 | 39 | } |
ridwangs7 | 1:f264a7ecd285 | 40 | } |
ridwangs7 | 1:f264a7ecd285 | 41 | } |
ridwangs7 | 1:f264a7ecd285 | 42 | } |
ridwangs7 | 1:f264a7ecd285 | 43 | } |
ridwangs7 | 1:f264a7ecd285 | 44 | return diceNum; |
ridwangs7 | 1:f264a7ecd285 | 45 | } |
ridwangs7 | 1:f264a7ecd285 | 46 | |
ridwangs7 | 1:f264a7ecd285 | 47 | |
ridwangs7 | 1:f264a7ecd285 | 48 | void draw_start(){ |
ridwangs7 | 1:f264a7ecd285 | 49 | ulcd.text_width(2); |
ridwangs7 | 1:f264a7ecd285 | 50 | ulcd.text_height(2); |
ridwangs7 | 1:f264a7ecd285 | 51 | ulcd.locate(2,2); |
ridwangs7 | 1:f264a7ecd285 | 52 | ulcd.printf("\n YAHTZEE"); |
ridwangs7 | 1:f264a7ecd285 | 53 | |
ridwangs7 | 1:f264a7ecd285 | 54 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 55 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 56 | ulcd.locate(4,8); |
ridwangs7 | 1:f264a7ecd285 | 57 | ulcd.printf("\n Press to Roll"); |
ridwangs7 | 1:f264a7ecd285 | 58 | |
ridwangs7 | 1:f264a7ecd285 | 59 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 60 | |
ridwangs7 | 1:f264a7ecd285 | 61 | |
ridwangs7 | 1:f264a7ecd285 | 62 | } |
ridwangs7 | 1:f264a7ecd285 | 63 | |
jwalker366 | 0:088af403d779 | 64 | |
ridwangs7 | 1:f264a7ecd285 | 65 | void draw_readyRoll(){ |
ridwangs7 | 1:f264a7ecd285 | 66 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 67 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 68 | ulcd.locate(4,1); |
ridwangs7 | 1:f264a7ecd285 | 69 | ulcd.printf("\n Ready to Roll"); |
ridwangs7 | 1:f264a7ecd285 | 70 | |
ridwangs7 | 1:f264a7ecd285 | 71 | ulcd.text_width(2); |
ridwangs7 | 1:f264a7ecd285 | 72 | ulcd.text_height(2); |
ridwangs7 | 1:f264a7ecd285 | 73 | ulcd.locate(2,1); |
ridwangs7 | 1:f264a7ecd285 | 74 | ulcd.printf("\n Press\n Roll\n Button\n 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 | |
ridwangs7 | 1:f264a7ecd285 | 81 | |
ridwangs7 | 1:f264a7ecd285 | 82 | void draw_diceDisp(){ |
ridwangs7 | 1:f264a7ecd285 | 83 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 84 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 85 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 86 | ulcd.printf("Do you want to select any dice?"); |
ridwangs7 | 1:f264a7ecd285 | 87 | |
ridwangs7 | 1:f264a7ecd285 | 88 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 89 | |
ridwangs7 | 1:f264a7ecd285 | 90 | |
ridwangs7 | 1:f264a7ecd285 | 91 | } |
ridwangs7 | 1:f264a7ecd285 | 92 | |
ridwangs7 | 1:f264a7ecd285 | 93 | |
ridwangs7 | 1:f264a7ecd285 | 94 | void draw_diceSelect(){ |
ridwangs7 | 1:f264a7ecd285 | 95 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 96 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 97 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 98 | ulcd.printf("Press button 1 to roll again"); |
ridwangs7 | 1:f264a7ecd285 | 99 | ulcd.printf("\n Press button 2 to break"); |
ridwangs7 | 1:f264a7ecd285 | 100 | |
ridwangs7 | 1:f264a7ecd285 | 101 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 102 | |
ridwangs7 | 1:f264a7ecd285 | 103 | |
ridwangs7 | 1:f264a7ecd285 | 104 | } |
ridwangs7 | 1:f264a7ecd285 | 105 | |
ridwangs7 | 1:f264a7ecd285 | 106 | |
ridwangs7 | 1:f264a7ecd285 | 107 | void draw_scoreScreen(){ |
ridwangs7 | 1:f264a7ecd285 | 108 | ulcd.text_width(1); |
ridwangs7 | 1:f264a7ecd285 | 109 | ulcd.text_height(1); |
ridwangs7 | 1:f264a7ecd285 | 110 | ulcd.locate(1,1); |
ridwangs7 | 1:f264a7ecd285 | 111 | ulcd.printf("Please score your round and reset."); |
ridwangs7 | 1:f264a7ecd285 | 112 | |
ridwangs7 | 1:f264a7ecd285 | 113 | // Processing |
ridwangs7 | 1:f264a7ecd285 | 114 | |
ridwangs7 | 1:f264a7ecd285 | 115 | |
ridwangs7 | 1:f264a7ecd285 | 116 | } |
ridwangs7 | 1:f264a7ecd285 | 117 | |
ridwangs7 | 1:f264a7ecd285 | 118 | int main() |
ridwangs7 | 1:f264a7ecd285 | 119 | { |
ridwangs7 | 1:f264a7ecd285 | 120 | ulcd.cls(); |
ridwangs7 | 1:f264a7ecd285 | 121 | ulcd.baudrate(3000000); //jack up baud rate to max for fast display |
ridwangs7 | 1:f264a7ecd285 | 122 | int selectedDice = 0; |
jwalker366 | 0:088af403d779 | 123 | while(1) { |
ridwangs7 | 1:f264a7ecd285 | 124 | draw_start(); |
ridwangs7 | 1:f264a7ecd285 | 125 | selectedDice = selectDice(); |
ridwangs7 | 1:f264a7ecd285 | 126 | pc.printf("Selected Dice: '%d %d'\n", selectedDice, selectedDiceArray[selectedDice]); |
ridwangs7 | 1:f264a7ecd285 | 127 | |
ridwangs7 | 1:f264a7ecd285 | 128 | /* pseudocode to match flow block diagram |
ridwangs7 | 1:f264a7ecd285 | 129 | but_pushed = -1; |
ridwangs7 | 1:f264a7ecd285 | 130 | while(but_pushed != 2){ // enter while if 1 pressed (yes) -> (initially -1) |
ridwangs7 | 1:f264a7ecd285 | 131 | but_pushed = -1; |
ridwangs7 | 1:f264a7ecd285 | 132 | while (but_pushed != 1){ |
ridwangs7 | 1:f264a7ecd285 | 133 | draw_readyRoll(); |
ridwangs7 | 1:f264a7ecd285 | 134 | draw_diceDisp(); |
ridwangs7 | 1:f264a7ecd285 | 135 | } |
ridwangs7 | 1:f264a7ecd285 | 136 | draw_diceSelect(); |
ridwangs7 | 1:f264a7ecd285 | 137 | } |
ridwangs7 | 1:f264a7ecd285 | 138 | */ |
ridwangs7 | 1:f264a7ecd285 | 139 | // draw_scoreScreen(); |
jwalker366 | 0:088af403d779 | 140 | } |
jwalker366 | 0:088af403d779 | 141 | } |