Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions FlappyLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "crash_animation.h"
#include "modes_animation.h"
#include "intro_animation.h"
#include <BleValueSync.h>


//#define DEBUG 1 //Enable debug prints in Serial Monitor : 115200

Expand All @@ -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*/
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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() {
Expand All @@ -137,7 +165,7 @@ void loop() {

if (game_ongoing) {
if(score == 0){
delay(800);
delay(500);
}

/* Remove the wall from the matrix */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}