implemented Team Button LEDs and tap out feature
This commit is contained in:
@@ -20,16 +20,4 @@ void pollInput (){
|
|||||||
buttonPIThold = buttonPIT.on();
|
buttonPIThold = buttonPIT.on();
|
||||||
buttonRESETvar = buttonRESET.longPress();
|
buttonRESETvar = buttonRESET.longPress();
|
||||||
}
|
}
|
||||||
// if (buttonREDTEAM.pushed()) {
|
|
||||||
// buttonREDTEAMvar = true;
|
|
||||||
// if (ARENA_READY && !REDTEAM_READY) {
|
|
||||||
// BLINK_COUNTER_REDTEAM = 5;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (buttonBLUETEAM.pushed()) {
|
|
||||||
// buttonBLUETEAMvar = true;
|
|
||||||
// if (ARENA_READY && !BLUETEAM_READY) {
|
|
||||||
// BLINK_COUNTER_BLUETEAM = 5;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -48,20 +48,69 @@ void statusLEDs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// usage: blink_LED_BlueTeam(<interval in milliseconds>);
|
void updateTEAMLEDs() {
|
||||||
// void blink_LED_BlueTeam(int BLINK_INTERVAL) {
|
if ((buttonREDTEAMvar == true) && (sendToREDTEAMbutton.TEAMLED == false)) {
|
||||||
|
sendToREDTEAMbutton.TEAMLED = true;
|
||||||
|
esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
|
}
|
||||||
|
// else if ((buttonREDTEAMvar == false) && (sendToREDTEAMbutton.TEAMLED == true)) {
|
||||||
|
// sendToREDTEAMbutton.TEAMLED = false;
|
||||||
|
// esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ((buttonBLUETEAMvar == true) && (sendToBLUETEAMbutton.TEAMLED == false)) {
|
||||||
|
sendToBLUETEAMbutton.TEAMLED = true;
|
||||||
|
esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
|
}
|
||||||
|
// else if ((buttonBLUETEAMvar == false) && (sendToBLUETEAMbutton.TEAMLED == true)) {
|
||||||
|
// sendToBLUETEAMbutton.TEAMLED = false;
|
||||||
|
// esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void REDTEAM_LED(bool STATE) {
|
||||||
|
if (STATE) {
|
||||||
|
sendToREDTEAMbutton.TEAMLED = true;
|
||||||
|
esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
|
} else {
|
||||||
|
sendToREDTEAMbutton.TEAMLED = false;
|
||||||
|
esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLUETEAM_LED(bool STATE) {
|
||||||
|
if (STATE) {
|
||||||
|
sendToBLUETEAMbutton.TEAMLED = true;
|
||||||
|
esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
|
} else {
|
||||||
|
sendToBLUETEAMbutton.TEAMLED = false;
|
||||||
|
esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// void blink_LED_BlueTeam() {
|
||||||
// EVERY_N_MILLISECONDS(BLINK_INTERVAL) {
|
// EVERY_N_MILLISECONDS(BLINK_INTERVAL) {
|
||||||
// if (BLINK_COUNTER_BLUETEAM-- > 0) {
|
// if (BLINK_COUNTER_BLUETEAM-- > 0) {
|
||||||
// digitalWrite(BLUE_TEAM_LED_PIN, !digitalRead(BLUE_TEAM_LED_PIN));
|
// if (sendToBLUETEAMbutton.TEAMLED == false) {
|
||||||
|
// sendToBLUETEAMbutton.TEAMLED = true;
|
||||||
|
// } else {
|
||||||
|
// sendToBLUETEAMbutton.TEAMLED = false;
|
||||||
|
// }
|
||||||
|
// esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// usage: blink_LED_RedTeam(<interval in milliseconds times two>);
|
|
||||||
// void blink_LED_RedTeam(int BLINK_INTERVAL) {
|
// void blink_LED_RedTeam() {
|
||||||
// EVERY_N_MILLISECONDS(BLINK_INTERVAL) {
|
// EVERY_N_MILLISECONDS(BLINK_INTERVAL) {
|
||||||
// if (BLINK_COUNTER_REDTEAM-- > 0) {
|
// if (BLINK_COUNTER_REDTEAM-- > 0) {
|
||||||
// digitalWrite(RED_TEAM_LED_PIN, !digitalRead(RED_TEAM_LED_PIN));
|
// if (sendToREDTEAMbutton.TEAMLED == false) {
|
||||||
|
// sendToREDTEAMbutton.TEAMLED = true;
|
||||||
|
// } else {
|
||||||
|
// sendToREDTEAMbutton.TEAMLED = false;
|
||||||
|
// }
|
||||||
|
// esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ bool buttonREDTEAMtapout = false;
|
|||||||
bool buttonBLUETEAMvar = false;
|
bool buttonBLUETEAMvar = false;
|
||||||
bool buttonBLUETEAMtapout = false;
|
bool buttonBLUETEAMtapout = false;
|
||||||
unsigned long PITopenTimestamp = 0;
|
unsigned long PITopenTimestamp = 0;
|
||||||
const long PITopenTime = 1000; // activate solenoid for 1000ms
|
|
||||||
bool PITreleased = false;
|
bool PITreleased = false;
|
||||||
|
|
||||||
const int countdownTIME = 100; // countdown timer length in seconds, actual countdown for the fight
|
const long PITopenTime = 500; // activate solenoid for 500ms
|
||||||
|
const int countdownTIME = 180; // countdown timer length in seconds, actual countdown for the fight
|
||||||
const int countdownToFightTIME = 3; // countdown timer length in seconds, "ready" countdown
|
const int countdownToFightTIME = 3; // countdown timer length in seconds, "ready" countdown
|
||||||
const int PITreleaseTime = 90; // automatic pit release time in seconds until end of countdown
|
const int PITreleaseTime = 90; // automatic pit release time in seconds until end of countdown
|
||||||
bool countdownPAUSED = false;
|
bool countdownPAUSED = false;
|
||||||
@@ -69,10 +69,12 @@ CountDown ReadyCountDown(CountDown::SECONDS);
|
|||||||
// Rumble stopwatch
|
// Rumble stopwatch
|
||||||
StopWatch rumbleTIME(StopWatch::SECONDS);
|
StopWatch rumbleTIME(StopWatch::SECONDS);
|
||||||
|
|
||||||
int CLOCK_LED_BRIGHTNESS = 16; // 64 is okay
|
int CLOCK_LED_BRIGHTNESS = 32; // 64 is okay
|
||||||
|
|
||||||
int BLINK_COUNTER_REDTEAM = 0;
|
int BLINK_COUNTER_REDTEAM = 0;
|
||||||
int BLINK_COUNTER_BLUETEAM = 0;
|
int BLINK_COUNTER_BLUETEAM = 0;
|
||||||
|
int BLINK_INTERVAL = 200;
|
||||||
|
|
||||||
|
|
||||||
bool ARENA_READY = false;
|
bool ARENA_READY = false;
|
||||||
bool REDTEAM_READY = false;
|
bool REDTEAM_READY = false;
|
||||||
@@ -108,6 +110,14 @@ typedef struct struct_message_send {
|
|||||||
struct_message_send sendToREDTEAMbutton;
|
struct_message_send sendToREDTEAMbutton;
|
||||||
struct_message_send sendToBLUETEAMbutton;
|
struct_message_send sendToBLUETEAMbutton;
|
||||||
|
|
||||||
|
// ESP-Now stuff for the Pit controller
|
||||||
|
uint8_t broadcastAddressPitController[] = {0x84, 0xFC, 0xE6, 0xC7, 0x19, 0xDE};
|
||||||
|
// Structure for sending data
|
||||||
|
typedef struct struct_message_pit {
|
||||||
|
bool PIT; // LED state
|
||||||
|
} struct_message_pit;
|
||||||
|
struct_message_pit sendToPitController;
|
||||||
|
|
||||||
esp_now_peer_info_t peerInfo;
|
esp_now_peer_info_t peerInfo;
|
||||||
|
|
||||||
// callback when data is sent
|
// callback when data is sent
|
||||||
@@ -245,12 +255,14 @@ void setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize both Team button LED states
|
// Initialize both Team button LED states and pit controller state
|
||||||
sendToREDTEAMbutton.TEAMLED = false;
|
sendToREDTEAMbutton.TEAMLED = false;
|
||||||
sendToBLUETEAMbutton.TEAMLED = false;
|
sendToBLUETEAMbutton.TEAMLED = false;
|
||||||
// reset remote button LEDs
|
sendToPitController.PIT = false;
|
||||||
|
// reset remote button LEDs and pit
|
||||||
esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
esp_now_send(broadcastAddressREDTEAMbutton, (uint8_t *)&sendToREDTEAMbutton, sizeof(sendToREDTEAMbutton));
|
||||||
esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
esp_now_send(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton));
|
||||||
|
esp_now_send(broadcastAddressPitController, (uint8_t *)&sendToPitController, sizeof(sendToPitController));
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// ESP Now receive part:
|
// ESP Now receive part:
|
||||||
@@ -259,6 +271,7 @@ void setup() {
|
|||||||
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
|
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int XDAS = 255;
|
int XDAS = 255;
|
||||||
bool toggle = false;
|
bool toggle = false;
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -270,6 +283,8 @@ void loop() {
|
|||||||
arenaLIGHT();
|
arenaLIGHT();
|
||||||
// update status LEDs
|
// update status LEDs
|
||||||
statusLEDs();
|
statusLEDs();
|
||||||
|
// update Teambutton LEDs
|
||||||
|
updateTEAMLEDs();
|
||||||
|
|
||||||
// start button logic
|
// start button logic
|
||||||
if (buttonSTARTvar) {
|
if (buttonSTARTvar) {
|
||||||
@@ -358,6 +373,31 @@ void loop() {
|
|||||||
if (rumbleTIME.elapsed() >= PITreleaseTime && switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
if (rumbleTIME.elapsed() >= PITreleaseTime && switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||||
openPIT();
|
openPIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tap out logic
|
||||||
|
if (buttonREDTEAMtapout && !switchRUMBLE.on()) {
|
||||||
|
countdownPAUSED = true;
|
||||||
|
FightCountDown.stop();
|
||||||
|
REDTEAM_LED(true);
|
||||||
|
sendTimeDisplay(99, 0, 255, 0, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(1500);
|
||||||
|
sendTimeDisplay(0, 99, 255, 0, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(1500);
|
||||||
|
sendTimeDisplay((FightCountDown.remaining()/60%60), (FightCountDown.remaining()%60), 255, 0, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(7000);
|
||||||
|
}
|
||||||
|
if (buttonBLUETEAMtapout && !switchRUMBLE.on()) {
|
||||||
|
countdownPAUSED = true;
|
||||||
|
FightCountDown.stop();
|
||||||
|
BLUETEAM_LED(true);
|
||||||
|
sendTimeDisplay(99, 0, 0, 0, 255, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(1500);
|
||||||
|
sendTimeDisplay(0, 99, 0, 0, 255, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(1500);
|
||||||
|
sendTimeDisplay((FightCountDown.remaining()/60%60), (FightCountDown.remaining()%60), 0, 0, 255, CLOCK_LED_BRIGHTNESS);
|
||||||
|
delay(1500);
|
||||||
|
}
|
||||||
|
|
||||||
// reset button logic
|
// reset button logic
|
||||||
if (buttonRESETvar) {
|
if (buttonRESETvar) {
|
||||||
buttonRESETvar = false;
|
buttonRESETvar = false;
|
||||||
@@ -368,6 +408,8 @@ void loop() {
|
|||||||
// Ready Countdown to Fight Countdown transition
|
// Ready Countdown to Fight Countdown transition
|
||||||
if (ReadyCountDown.remaining() == 0 && ARENA_READY) {
|
if (ReadyCountDown.remaining() == 0 && ARENA_READY) {
|
||||||
ARENA_READY = false;
|
ARENA_READY = false;
|
||||||
|
REDTEAM_LED(false);
|
||||||
|
BLUETEAM_LED(false);
|
||||||
if (!switchRUMBLE.on()) {
|
if (!switchRUMBLE.on()) {
|
||||||
FightCountDown.start(countdownTIME);
|
FightCountDown.start(countdownTIME);
|
||||||
} else if (switchRUMBLE.on()) {
|
} else if (switchRUMBLE.on()) {
|
||||||
@@ -375,21 +417,20 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//blink_LED_RedTeam(200);
|
|
||||||
//blink_LED_BlueTeam(200);
|
|
||||||
|
|
||||||
// update the LED Display
|
// update the LED Display
|
||||||
if (ReadyCountDown.isRunning()) {
|
if (!(buttonREDTEAMtapout || buttonBLUETEAMtapout)) {
|
||||||
sendTimeDisplay((ReadyCountDown.remaining()/60%60), (ReadyCountDown.remaining()%60), XDAS, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
if (ReadyCountDown.isRunning()) {
|
||||||
} else {
|
sendTimeDisplay((ReadyCountDown.remaining()/60%60), (ReadyCountDown.remaining()%60), 255, 165, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
if (!switchRUMBLE.on()) {
|
} else {
|
||||||
if (!FightCountDown.isRunning() && countdownPAUSED == false) {
|
if (!switchRUMBLE.on()) {
|
||||||
sendTimeDisplay((countdownTIME/60%60), (countdownTIME%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
if (!FightCountDown.isRunning() && countdownPAUSED == false) {
|
||||||
} else {
|
sendTimeDisplay((countdownTIME/60%60), (countdownTIME%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
sendTimeDisplay((FightCountDown.remaining()/60%60), (FightCountDown.remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
} else {
|
||||||
|
sendTimeDisplay((FightCountDown.remaining()/60%60), (FightCountDown.remaining()%60), 0, 255, 0, CLOCK_LED_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
} else if (switchRUMBLE.on()) {
|
||||||
|
sendTimeDisplay((rumbleTIME.elapsed()/60%60), (rumbleTIME.elapsed()%60), 0, 255, 255, CLOCK_LED_BRIGHTNESS);
|
||||||
}
|
}
|
||||||
} else if (switchRUMBLE.on()) {
|
|
||||||
sendTimeDisplay((rumbleTIME.elapsed()/60%60), (rumbleTIME.elapsed()%60), 0, XDAS, XDAS, CLOCK_LED_BRIGHTNESS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user