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
39 changes: 33 additions & 6 deletions LedPong.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Modulino.h>
#include <Scheduler.h>
#include <Arduino_LED_Matrix.h>
#include <BleValueSync.h>
#include "crash.h"
#include "pong_start.h"
#include "winner.h"
Expand All @@ -11,7 +12,8 @@
#define BUZZER 1
#define ANIMATION 1
#define LEDS 1
#define BACKGROUND_LEDS 1
//#define BACKGROUND_LEDS 1
#define BLE_SYNC 1

/* Defines */
#define SECONDARY_ENCODER_ADDRESS 0x08
Expand Down Expand Up @@ -67,6 +69,14 @@ 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("LedPong", "76095e25-2eda-43c3-9289-f699b4800d2e", 3);
BleSyncValue bleCounter("25bf4001-6fb0-4e91-8ee2-8b218c1930db", BLERead | BLEWrite);
BleSyncValue bleLeftWinner("e6a264b5-32dc-456e-aeb1-07e63189ec7b", BLERead | BLEWrite);
BleSyncValue bleRightWinner("12bd8f99-2d1f-458f-baf0-47ed72c0a1c8", BLERead | BLEWrite);
#endif

void setup() {
// put your setup code here, to run once:

Expand Down Expand Up @@ -115,6 +125,13 @@ void setup() {
Scheduler.startLoop(playerDXLoop);
Scheduler.startLoop(playerSXLoop);

#ifdef BLE_SYNC
ble.addValue(&bleCounter);
ble.addValue(&bleLeftWinner);
ble.addValue(&bleRightWinner);
ble.initBLE();
#endif

game_ongoing = 1;

#ifdef DEBUG
Expand Down Expand Up @@ -335,7 +352,13 @@ void resetVariables(){
dxEncoder.set(START_Y);
sxEncoder.set(START_Y);

#ifndef BLE_SYNC
delay(1500);
#endif

#ifdef BLE_SYNC
ble.sync(3000);
#endif

muted = 1;
game_ongoing = 1;
Expand Down Expand Up @@ -365,6 +388,15 @@ void handleMatch(int8_t winner){
if(win_right == MATCH_TO_WIN || win_left == MATCH_TO_WIN){
showVictoryAnimation(winner);

#ifdef BLE_SYNC
bleCounter.setValue(bleCounter.getValue()+1);
if(winner == LEFT_WIN){
bleLeftWinner.setValue(bleLeftWinner.getValue()+1);
} else {
bleRightWinner.setValue(bleRightWinner.getValue()+1);
}
#endif

win_right = 0;
win_left = 0;
}
Expand Down Expand Up @@ -467,8 +499,3 @@ void flickerBackground(){

}
#endif