diff --git a/FlappyLED.ino b/FlappyLED.ino index 7552415..c3dd15b 100644 --- a/FlappyLED.ino +++ b/FlappyLED.ino @@ -6,6 +6,8 @@ #include "crash_animation.h" #include "modes_animation.h" #include "intro_animation.h" +#include + //#define DEBUG 1 //Enable debug prints in Serial Monitor : 115200 @@ -30,6 +32,7 @@ #define BUZZER //Modulino Buzzer needed: play sounds while playing #define ANIMATIONS //Enable Animations #define RESET_TIME //Automatically reset after some time +#define BLE_SYNC 1 //Enable BLE Sync /* Game Modes */ /* It is the state of the game*/ @@ -67,6 +70,18 @@ byte frame[8][12] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; + +#ifdef BLE_SYNC +/* BT Service and properties */ +BleSync ble("FlappyLed", "d4d1cb67-d83e-41b6-bfc9-95d25ca6a91d", 5); +BleSyncValue bleRecordEncoder("a3cd7bd3-4d6e-492f-9f18-f9bf181be541", BLERead | BLEWrite); +BleSyncValue bleGamesEncoder("59802c1a-c0d8-4b35-9c6c-b258304e078b", BLERead | BLEWrite); +BleSyncValue bleRecordTof("2380e50e-562d-4e46-aeaf-d73b9d258f73", BLERead | BLEWrite); +BleSyncValue bleGamesTof("a8dd61cd-02b9-465b-8f6d-a185aa65bce0", BLERead | BLEWrite); +BleSyncValue bleCounter("17a8a342-41bd-4dc0-98af-62d30a0d4432", BLERead | BLEWrite); +#endif + + void setup() { // put your setup code here, to run once: @@ -113,6 +128,19 @@ void setup() { digitalWrite(LED_BUILTIN, HIGH); #endif + #ifdef BLE_SYNC + + ble.addValue(&bleRecordEncoder); + ble.addValue(&bleCounter); + ble.addValue(&bleGamesEncoder); + ble.addValue(&bleRecordTof); + ble.addValue(&bleGamesTof); + ble.addValue(&bleCounter); + ble.initBLE(); + + #endif + + } void loop() { @@ -137,7 +165,7 @@ void loop() { if (game_ongoing) { if(score == 0){ - delay(800); + delay(500); } /* Remove the wall from the matrix */ @@ -519,6 +547,23 @@ void clear_text() void resetGameState() { + #ifdef BLE_SYNC + /* Store local record */ + + if(gameMode == ENCODER) { + if(score > bleRecordEncoder.getValue()){ + bleRecordEncoder.setValue(score); + } + bleGamesEncoder.setValue(bleGamesEncoder.getValue()+1); + } else if(gameMode == TOF) { + if(score > bleRecordTof.getValue()){ + bleRecordTof.setValue(score); + } + bleGamesTof.setValue(bleGamesTof.getValue()+1); + } + bleCounter.setValue(bleCounter.getValue()+1); + #endif + /* Reset game mode*/ gameMode = MENU; @@ -564,7 +609,14 @@ void resetGameState() tofOldDistance = 0; /*Wait some time after finish*/ - delay(3000); + #if !defined(BLE_SYNC) + delay(4000); + #endif + + #ifdef BLE_SYNC + ble.sync(4000); + #endif + clear_text(); game_ongoing = 0; }