Bluetooth
Dependencies: 4DGL-uLCD-SE mbed MMA8452 PinDetect SDFileSystem wave_player
Diff: main.cpp
- Revision:
- 1:f264a7ecd285
- Parent:
- 0:088af403d779
- Child:
- 2:655c8a5c2ad8
--- a/main.cpp Mon Nov 21 19:02:00 2022 +0000 +++ b/main.cpp Fri Dec 02 17:46:34 2022 +0000 @@ -1,12 +1,141 @@ +/* + Jared Walker + Ridwan Sadiq + Emanuel Abdul-Salaam + Juan Padilla +*/ + #include "mbed.h" +#include "uLCD_4DGL.h" + +BusOut myled(LED1,LED2,LED3,LED4); +Serial blue(p9,p10); +Serial pc(USBTX, USBRX); +uLCD_4DGL ulcd(p13,p14,p11); + + +int but_pushed = -1; // ==1 -> pb1 pushed, == 2 -> pb2 pushed +bool selectedDiceArray[5]; + -DigitalOut myled(LED1); +int selectDice() +{ + char bnum=0; + char bhit=0; + int diceNum = 0; + + if (blue.getc()=='!') { + if (blue.getc()=='B') { //button data packet + bnum = blue.getc(); //button number + bhit = blue.getc(); //1=hit, 0=release + if (blue.getc()==char(~('!' + 'B' + bnum + bhit))) { //checksum OK? + if ((bnum>='1')&&(bnum<='5')){ //is a number button 1..4 + diceNum = bnum-48; + selectedDiceArray[diceNum]= 1; + if (bhit=='1') { + myled = bnum - '0'; + } else { + myled = '0'; + } + } + } + } + } + return diceNum; +} + + +void draw_start(){ + ulcd.text_width(2); + ulcd.text_height(2); + ulcd.locate(2,2); + ulcd.printf("\n YAHTZEE"); + + ulcd.text_width(1); + ulcd.text_height(1); + ulcd.locate(4,8); + ulcd.printf("\n Press to Roll"); + + // Processing + + +} + -int main() { +void draw_readyRoll(){ + ulcd.text_width(1); + ulcd.text_height(1); + ulcd.locate(4,1); + ulcd.printf("\n Ready to Roll"); + + ulcd.text_width(2); + ulcd.text_height(2); + ulcd.locate(2,1); + ulcd.printf("\n Press\n Roll\n Button\n to Roll"); + + // Processing + + +} + + +void draw_diceDisp(){ + ulcd.text_width(1); + ulcd.text_height(1); + ulcd.locate(1,1); + ulcd.printf("Do you want to select any dice?"); + + // Processing + + +} + + +void draw_diceSelect(){ + ulcd.text_width(1); + ulcd.text_height(1); + ulcd.locate(1,1); + ulcd.printf("Press button 1 to roll again"); + ulcd.printf("\n Press button 2 to break"); + + // Processing + + +} + + +void draw_scoreScreen(){ + ulcd.text_width(1); + ulcd.text_height(1); + ulcd.locate(1,1); + ulcd.printf("Please score your round and reset."); + + // Processing + + +} + +int main() +{ + ulcd.cls(); + ulcd.baudrate(3000000); //jack up baud rate to max for fast display + int selectedDice = 0; while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + draw_start(); + selectedDice = selectDice(); + pc.printf("Selected Dice: '%d %d'\n", selectedDice, selectedDiceArray[selectedDice]); + + /* pseudocode to match flow block diagram + but_pushed = -1; + while(but_pushed != 2){ // enter while if 1 pressed (yes) -> (initially -1) + but_pushed = -1; + while (but_pushed != 1){ + draw_readyRoll(); + draw_diceDisp(); + } + draw_diceSelect(); + } + */ +// draw_scoreScreen(); } }