diff --git a/ROFLS_Arena_Controller/Input_Handler.ino b/ROFLS_Arena_Controller/Input_Handler.ino index 9c658b2..dd61b39 100644 --- a/ROFLS_Arena_Controller/Input_Handler.ino +++ b/ROFLS_Arena_Controller/Input_Handler.ino @@ -20,16 +20,4 @@ void pollInput (){ buttonPIThold = buttonPIT.on(); 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; - // } - // } } \ No newline at end of file diff --git a/ROFLS_Arena_Controller/Output_Handler.ino b/ROFLS_Arena_Controller/Output_Handler.ino index 77b274f..4e26169 100644 --- a/ROFLS_Arena_Controller/Output_Handler.ino +++ b/ROFLS_Arena_Controller/Output_Handler.ino @@ -48,20 +48,69 @@ void statusLEDs() { } } -// usage: blink_LED_BlueTeam(); -// void blink_LED_BlueTeam(int BLINK_INTERVAL) { +void updateTEAMLEDs() { + 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) { // 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(); -// void blink_LED_RedTeam(int BLINK_INTERVAL) { + +// void blink_LED_RedTeam() { // EVERY_N_MILLISECONDS(BLINK_INTERVAL) { // 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)); // } // } -// } \ No newline at end of file +// } diff --git a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino index cd32488..82f3ee5 100644 --- a/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino +++ b/ROFLS_Arena_Controller/ROFLS_Arena_Controller.ino @@ -56,10 +56,10 @@ bool buttonREDTEAMtapout = false; bool buttonBLUETEAMvar = false; bool buttonBLUETEAMtapout = false; unsigned long PITopenTimestamp = 0; -const long PITopenTime = 1000; // activate solenoid for 1000ms 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 PITreleaseTime = 90; // automatic pit release time in seconds until end of countdown bool countdownPAUSED = false; @@ -69,10 +69,12 @@ CountDown ReadyCountDown(CountDown::SECONDS); // Rumble stopwatch 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_BLUETEAM = 0; +int BLINK_INTERVAL = 200; + bool ARENA_READY = false; bool REDTEAM_READY = false; @@ -108,6 +110,14 @@ typedef struct struct_message_send { struct_message_send sendToREDTEAMbutton; 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; // callback when data is sent @@ -245,12 +255,14 @@ void setup() { return; } - // Initialize both Team button LED states + // Initialize both Team button LED states and pit controller state sendToREDTEAMbutton.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(broadcastAddressBLUETEAMbutton, (uint8_t *)&sendToBLUETEAMbutton, sizeof(sendToBLUETEAMbutton)); + esp_now_send(broadcastAddressPitController, (uint8_t *)&sendToPitController, sizeof(sendToPitController)); //------------------------------------------------------------------------------------ // ESP Now receive part: @@ -259,6 +271,7 @@ void setup() { esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv)); } + int XDAS = 255; bool toggle = false; void loop() { @@ -270,6 +283,8 @@ void loop() { arenaLIGHT(); // update status LEDs statusLEDs(); + // update Teambutton LEDs + updateTEAMLEDs(); // start button logic if (buttonSTARTvar) { @@ -358,6 +373,31 @@ void loop() { if (rumbleTIME.elapsed() >= PITreleaseTime && switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) { 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 if (buttonRESETvar) { buttonRESETvar = false; @@ -368,6 +408,8 @@ void loop() { // Ready Countdown to Fight Countdown transition if (ReadyCountDown.remaining() == 0 && ARENA_READY) { ARENA_READY = false; + REDTEAM_LED(false); + BLUETEAM_LED(false); if (!switchRUMBLE.on()) { FightCountDown.start(countdownTIME); } else if (switchRUMBLE.on()) { @@ -375,21 +417,20 @@ void loop() { } } - //blink_LED_RedTeam(200); - //blink_LED_BlueTeam(200); - // update the LED Display - if (ReadyCountDown.isRunning()) { - sendTimeDisplay((ReadyCountDown.remaining()/60%60), (ReadyCountDown.remaining()%60), XDAS, XDAS, 0, CLOCK_LED_BRIGHTNESS); - } else { - if (!switchRUMBLE.on()) { - if (!FightCountDown.isRunning() && countdownPAUSED == false) { - sendTimeDisplay((countdownTIME/60%60), (countdownTIME%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS); - } else { - sendTimeDisplay((FightCountDown.remaining()/60%60), (FightCountDown.remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS); + if (!(buttonREDTEAMtapout || buttonBLUETEAMtapout)) { + if (ReadyCountDown.isRunning()) { + sendTimeDisplay((ReadyCountDown.remaining()/60%60), (ReadyCountDown.remaining()%60), 255, 165, 0, CLOCK_LED_BRIGHTNESS); + } else { + if (!switchRUMBLE.on()) { + if (!FightCountDown.isRunning() && countdownPAUSED == false) { + sendTimeDisplay((countdownTIME/60%60), (countdownTIME%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); } } }