adjusted code to actual hardware, added 'ready' countdown
This commit is contained in:
@@ -8,6 +8,8 @@ void pollInput (){
|
||||
buttonRESET.poll();
|
||||
switchRUMBLE.poll();
|
||||
switchPIT.poll();
|
||||
switchLIGHT.poll();
|
||||
switchTESTmode.poll();
|
||||
|
||||
// only set the var if the button was actually pushed or released, to prevent overriding data from the remote
|
||||
if (buttonSTART.singleClick() || buttonSTART.longPress() || buttonPAUSE.singleClick() || buttonPIT.singleClick() || buttonPIT.switched() || buttonRESET.longPress()) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
void checkPIT() {
|
||||
if ((digitalRead(PIT_RELEASE_PIN)) && (millis() - PITopenTimestamp >= PITopenTime)) {
|
||||
digitalWrite(PIT_RELEASE_PIN, LOW);
|
||||
if ((digitalRead(!PIT_RELEASE_PIN)) && (millis() - PITopenTimestamp >= PITopenTime)) {
|
||||
digitalWrite(PIT_RELEASE_PIN, relayOffState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,44 @@ void openPIT() {
|
||||
if (!PITreleased) {
|
||||
PITreleased = true;
|
||||
PITopenTimestamp = millis();
|
||||
digitalWrite(PIT_RELEASE_PIN, HIGH);
|
||||
digitalWrite(PIT_RELEASE_PIN, relayOnState);
|
||||
}
|
||||
}
|
||||
|
||||
void openPITmanually() {
|
||||
PITreleased = true;
|
||||
PITopenTimestamp = millis();
|
||||
digitalWrite(PIT_RELEASE_PIN, HIGH);
|
||||
digitalWrite(PIT_RELEASE_PIN, relayOnState);
|
||||
}
|
||||
|
||||
void arenaLIGHT() {
|
||||
if (switchLIGHT.on()) {
|
||||
digitalWrite(LIGHT_PIN, LOW);
|
||||
}
|
||||
else {
|
||||
digitalWrite(LIGHT_PIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void statusLEDs() {
|
||||
if (!switchLIGHT.on()) {
|
||||
digitalWrite(LIGHT_STATUS_LED, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(LIGHT_STATUS_LED, LOW);
|
||||
}
|
||||
if (switchPIT.on()) {
|
||||
digitalWrite(AUTOPIT_STATUS_LED, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(AUTOPIT_STATUS_LED, LOW);
|
||||
}
|
||||
if (switchRUMBLE.on()) {
|
||||
digitalWrite(MODE_STATUS_LED, HIGH);
|
||||
}
|
||||
else {
|
||||
digitalWrite(MODE_STATUS_LED, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
// usage: blink_LED_BlueTeam(<interval in milliseconds>);
|
||||
|
||||
@@ -9,13 +9,28 @@
|
||||
#include <StopWatch.h> // https://github.com/RobTillaart/StopWatch_RT
|
||||
|
||||
// Hardware connections
|
||||
// Buttons:
|
||||
#define START_BTN_PIN 1
|
||||
#define PAUSE_BTN_PIN 2
|
||||
#define PIT_BTN_PIN 3
|
||||
#define RESET_BTN_PIN 4
|
||||
#define RUMBLE_SWITCH_PIN 5
|
||||
#define PIT_ENABLE_SWITCH_PIN 6
|
||||
#define PIT_RELEASE_PIN 39
|
||||
#define PAUSE_BTN_PIN 3
|
||||
#define PIT_BTN_PIN 5
|
||||
#define RESET_BTN_PIN 7
|
||||
// Switches:
|
||||
#define RUMBLE_SWITCH_PIN 9
|
||||
#define PIT_ENABLE_SWITCH_PIN 11
|
||||
#define LIGHT_SWITCH_PIN 12
|
||||
#define TESTmode_SWITCH_PIN 4
|
||||
// LEDs:
|
||||
#define LIGHT_STATUS_LED 10
|
||||
#define AUTOPIT_STATUS_LED 13
|
||||
#define MODE_STATUS_LED 14
|
||||
// Relays:
|
||||
#define PIT_RELEASE_PIN 37
|
||||
#define LIGHT_PIN 39
|
||||
#define UNUSED_RELAY3_PIN 35
|
||||
#define UNUSED_RELAY4_PIN 33
|
||||
|
||||
const byte relayOnState = LOW;
|
||||
const byte relayOffState = HIGH;
|
||||
|
||||
// define buttons and switches
|
||||
//
|
||||
@@ -27,6 +42,8 @@ Switch buttonPIT = Switch(PIT_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
||||
Switch buttonRESET = Switch(RESET_BTN_PIN, INPUT_PULLUP, LOW, 50, 1000);
|
||||
Switch switchRUMBLE = Switch(RUMBLE_SWITCH_PIN);
|
||||
Switch switchPIT = Switch(PIT_ENABLE_SWITCH_PIN);
|
||||
Switch switchLIGHT = Switch(LIGHT_SWITCH_PIN);
|
||||
Switch switchTESTmode = Switch(TESTmode_SWITCH_PIN);
|
||||
|
||||
bool buttonSTARTvar = false;
|
||||
bool buttonSTARTforced = false;
|
||||
@@ -42,11 +59,12 @@ unsigned long PITopenTimestamp = 0;
|
||||
const long PITopenTime = 1000; // activate solenoid for 1000ms
|
||||
bool PITreleased = false;
|
||||
|
||||
const int countdownTIME = 3; // countdown timer length in minutes
|
||||
const int countdownToFight = 3; // countdown timer length in seconds
|
||||
const int countdownTIME = 100; // 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;
|
||||
CountDown FightCountDown[1];
|
||||
CountDown FightCountDown(CountDown::SECONDS);
|
||||
CountDown ReadyCountDown(CountDown::SECONDS);
|
||||
|
||||
// Rumble stopwatch
|
||||
StopWatch rumbleTIME(StopWatch::SECONDS);
|
||||
@@ -56,7 +74,7 @@ int CLOCK_LED_BRIGHTNESS = 16; // 64 is okay
|
||||
int BLINK_COUNTER_REDTEAM = 0;
|
||||
int BLINK_COUNTER_BLUETEAM = 0;
|
||||
|
||||
bool ARENA_READY = true;
|
||||
bool ARENA_READY = false;
|
||||
bool REDTEAM_READY = false;
|
||||
bool BLUETEAM_READY = false;
|
||||
|
||||
@@ -157,9 +175,22 @@ void sendTimeDisplay(int MINUTES, int SECONDS, int RED, int GREEN, int BLUE, int
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// set outputs
|
||||
// set relay outputs:
|
||||
pinMode(PIT_RELEASE_PIN, OUTPUT);
|
||||
digitalWrite(PIT_RELEASE_PIN, LOW);
|
||||
digitalWrite(PIT_RELEASE_PIN, relayOffState);
|
||||
pinMode(LIGHT_PIN, OUTPUT);
|
||||
digitalWrite(LIGHT_PIN, LOW); // have it by default on, to prevent flickering, needs a better fix tho
|
||||
pinMode(UNUSED_RELAY3_PIN, OUTPUT);
|
||||
digitalWrite(UNUSED_RELAY3_PIN, relayOffState);
|
||||
pinMode(UNUSED_RELAY4_PIN, OUTPUT);
|
||||
digitalWrite(UNUSED_RELAY4_PIN, relayOffState);
|
||||
// set status LED outputs:
|
||||
pinMode(LIGHT_STATUS_LED, OUTPUT);
|
||||
digitalWrite(LIGHT_PIN, HIGH); // have it by default on, to prevent flickering, needs a better fix tho
|
||||
pinMode(AUTOPIT_STATUS_LED, OUTPUT);
|
||||
digitalWrite(AUTOPIT_STATUS_LED, LOW);
|
||||
pinMode(MODE_STATUS_LED, OUTPUT);
|
||||
digitalWrite(MODE_STATUS_LED, LOW);
|
||||
|
||||
// Set device as a Wi-Fi Station
|
||||
WiFi.mode(WIFI_STA);
|
||||
@@ -207,27 +238,37 @@ void loop() {
|
||||
pollInput();
|
||||
// deactivate solenoids if needed
|
||||
checkPIT();
|
||||
// Arena Light
|
||||
arenaLIGHT();
|
||||
// update status LEDs
|
||||
statusLEDs();
|
||||
|
||||
// start button logic
|
||||
if (buttonSTARTvar) {
|
||||
buttonSTARTvar = false;
|
||||
if (!FightCountDown[0].isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) {
|
||||
// start logic
|
||||
if (!FightCountDown.isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) {
|
||||
if (switchRUMBLE.on()) {
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
rumbleTIME.start();
|
||||
//rumbleTIME.start();
|
||||
ARENA_READY = true;
|
||||
ReadyCountDown.start(countdownToFightTIME);
|
||||
} else if (buttonREDTEAMvar && buttonBLUETEAMvar && !switchRUMBLE.on()) {
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
FightCountDown[0].start(0,0,countdownTIME,0);
|
||||
//FightCountDown.start(countdownTIME);
|
||||
ARENA_READY = true;
|
||||
ReadyCountDown.start(countdownToFightTIME);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// resume logic
|
||||
if (buttonREDTEAMvar && buttonBLUETEAMvar && !switchRUMBLE.on()) {
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
countdownPAUSED = false;
|
||||
FightCountDown[0].cont();
|
||||
FightCountDown.resume();
|
||||
} else if (switchRUMBLE.on()) {
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
@@ -239,21 +280,26 @@ void loop() {
|
||||
// forced start of countdown
|
||||
if (buttonSTARTforced) {
|
||||
buttonSTARTforced = false;
|
||||
if (!FightCountDown[0].isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) {
|
||||
if (!FightCountDown.isRunning() && !rumbleTIME.isRunning() && countdownPAUSED == false) {
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
if (!switchRUMBLE.on()) {
|
||||
FightCountDown[0].start(0,0,countdownTIME,0);
|
||||
//FightCountDown.start(countdownTIME);
|
||||
ARENA_READY = true;
|
||||
ReadyCountDown.start(countdownToFightTIME);
|
||||
} else if (switchRUMBLE.on()) {
|
||||
rumbleTIME.start();
|
||||
//rumbleTIME.start();
|
||||
ARENA_READY = true;
|
||||
ReadyCountDown.start(countdownToFightTIME);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// forced resume logic
|
||||
buttonREDTEAMvar = false;
|
||||
buttonBLUETEAMvar = false;
|
||||
countdownPAUSED = false;
|
||||
if (!switchRUMBLE.on()) {
|
||||
FightCountDown[0].cont();
|
||||
FightCountDown.resume();
|
||||
} else if (switchRUMBLE.on()) {
|
||||
rumbleTIME.start();
|
||||
}
|
||||
@@ -262,9 +308,9 @@ void loop() {
|
||||
// pause button logic
|
||||
if (buttonPAUSEvar) {
|
||||
buttonPAUSEvar = false;
|
||||
if (FightCountDown[0].isRunning()) {
|
||||
if (FightCountDown.isRunning()) {
|
||||
countdownPAUSED = true;
|
||||
FightCountDown[0].stop();
|
||||
FightCountDown.stop();
|
||||
}
|
||||
if (rumbleTIME.isRunning()) {
|
||||
countdownPAUSED = true;
|
||||
@@ -278,7 +324,7 @@ void loop() {
|
||||
openPITmanually();
|
||||
}
|
||||
// automatic pit release
|
||||
if (FightCountDown[0].remaining() <= PITreleaseTime && FightCountDown[0].remaining() != 0 && !switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||
if (FightCountDown.remaining() <= PITreleaseTime && FightCountDown.remaining() != 0 && !switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||
openPIT();
|
||||
}
|
||||
if (rumbleTIME.elapsed() >= PITreleaseTime && switchRUMBLE.on() && switchPIT.on() && buttonPIThold == false) {
|
||||
@@ -290,16 +336,32 @@ void loop() {
|
||||
PITreleased = false;
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
// Ready Countdown to Fight Countdown transition
|
||||
if (ReadyCountDown.remaining() == 0 && ARENA_READY) {
|
||||
ARENA_READY = false;
|
||||
if (!switchRUMBLE.on()) {
|
||||
FightCountDown.start(countdownTIME);
|
||||
} else if (switchRUMBLE.on()) {
|
||||
rumbleTIME.start();
|
||||
}
|
||||
}
|
||||
|
||||
//blink_LED_RedTeam(200);
|
||||
//blink_LED_BlueTeam(200);
|
||||
|
||||
// update the LED Display
|
||||
if (!switchRUMBLE.on()) {
|
||||
if (!FightCountDown[0].isRunning() && countdownPAUSED == false) {
|
||||
sendTimeDisplay(countdownTIME, 0, 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
||||
if (ReadyCountDown.isRunning()) {
|
||||
sendTimeDisplay((ReadyCountDown.remaining()/60%60), (ReadyCountDown.remaining()%60), XDAS, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
||||
} else {
|
||||
sendTimeDisplay((FightCountDown[0].remaining()/60%60), (FightCountDown[0].remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
||||
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);
|
||||
}
|
||||
} else if (switchRUMBLE.on()) {
|
||||
sendTimeDisplay((rumbleTIME.elapsed()/60%60), (rumbleTIME.elapsed()%60), 0, XDAS, XDAS, CLOCK_LED_BRIGHTNESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ int boardID = 0;
|
||||
|
||||
|
||||
// Hardware connections
|
||||
#define START_BTN_PIN 1
|
||||
#define PAUSE_BTN_PIN 2
|
||||
#define PIT_BTN_PIN 3
|
||||
#define RESET_BTN_PIN 4
|
||||
#define START_BTN_PIN 10
|
||||
#define PAUSE_BTN_PIN 8
|
||||
#define PIT_BTN_PIN 1
|
||||
#define RESET_BTN_PIN 3
|
||||
#define TEAM_BTN_PIN 16
|
||||
#define TEAM_LED_PIN 17
|
||||
|
||||
|
||||
1317
Schematics/ESP32-S2_Interface_Board.diy
Normal file
1317
Schematics/ESP32-S2_Interface_Board.diy
Normal file
File diff suppressed because it is too large
Load Diff
1296
Schematics/MOSFET_Switching_Board.diy
Normal file
1296
Schematics/MOSFET_Switching_Board.diy
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user