removed not used code anymore from the controller firmware, added ESP-NOW functions and settings to the controller to control the display
This commit is contained in:
@@ -15,20 +15,7 @@
|
||||
#define RESET_BTN_PIN 4
|
||||
#define RUMBLE_SWITCH_PIN 5
|
||||
#define PIT_ENABLE_SWITCH_PIN 6
|
||||
#define RED_TEAM_BTN_PIN 7
|
||||
#define RED_TEAM_LED_PIN 39
|
||||
#define BLUE_TEAM_BTN_PIN 6
|
||||
#define BLUE_TEAM_LED_PIN 40
|
||||
#define PIT_RELEASE_PIN 35
|
||||
|
||||
// LED Strip setup
|
||||
#define NUM_LEDS_PER_DIGIT 56
|
||||
#define NUM_OF_DIGITS 4
|
||||
#define NUM_LEDS_COLON 8
|
||||
#define NUM_LEDS_TIMER (NUM_LEDS_PER_DIGIT * NUM_OF_DIGITS + NUM_LEDS_COLON) // + 1 because of the makeshift Levelshifter
|
||||
#define LED_DATA_PIN_TIMER 16
|
||||
// This is an array of leds. One item for each led in your strip.
|
||||
CRGB leds_TIMER[NUM_LEDS_TIMER];
|
||||
#define PIT_RELEASE_PIN 39
|
||||
|
||||
// define buttons and switches
|
||||
Switch buttonSTART = Switch(START_BTN_PIN);
|
||||
@@ -37,8 +24,6 @@ Switch buttonPIT = Switch(PIT_BTN_PIN);
|
||||
Switch buttonRESET = Switch(RESET_BTN_PIN);
|
||||
Switch switchRUMBLE = Switch(RUMBLE_SWITCH_PIN);
|
||||
Switch switchPIT = Switch(PIT_ENABLE_SWITCH_PIN);
|
||||
Switch buttonREDTEAM = Switch(RED_TEAM_BTN_PIN);
|
||||
Switch buttonBLUETEAM = Switch(BLUE_TEAM_BTN_PIN);
|
||||
|
||||
bool buttonSTARTvar = false;
|
||||
bool buttonPAUSEvar = false;
|
||||
@@ -59,12 +44,6 @@ CountDown FightCountDown[1];
|
||||
// Rumble stopwatch
|
||||
StopWatch rumbleTIME;
|
||||
|
||||
int prevMINUTES = 0;
|
||||
int prevSECONDS = 0;
|
||||
int prevCLOCKRED = 0;
|
||||
int prevCLOCKGREEN = 0;
|
||||
int prevCLOCKBLUE = 0;
|
||||
|
||||
int CLOCK_LED_BRIGHTNESS = 16; // 64 is okay
|
||||
|
||||
int BLINK_COUNTER_REDTEAM = 0;
|
||||
@@ -74,51 +53,106 @@ bool ARENA_READY = true;
|
||||
bool REDTEAM_READY = false;
|
||||
bool BLUETEAM_READY = false;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// ESP-NOW config
|
||||
// send config, Clock:
|
||||
uint8_t broadcastAddressClock[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
|
||||
// struct for clock data
|
||||
typedef struct struct_message_Clock {
|
||||
int sendMinutes;
|
||||
int sendSeconds;
|
||||
int sendREDchannel;
|
||||
int sendGREENchannel;
|
||||
int sendBLUEchannel;
|
||||
int sendBrightness;
|
||||
} struct_message_Clock;
|
||||
|
||||
|
||||
struct_message_Clock sendClockDATA;
|
||||
|
||||
// send config, pilot buttons:
|
||||
uint8_t broadcastAddressREDTEAMbutton[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
|
||||
uint8_t broadcastAddressBLUETEAMbutton[] = {0x48, 0x27, 0xE2, 0x5D, 0xB6, 0x84};
|
||||
// struct for pilot button data:
|
||||
typedef struct struct_message_TEAMButton {
|
||||
bool REDTEAMButtonLED;
|
||||
bool BLUETEAMButtonLED;
|
||||
} struct_message_TEAMButton;
|
||||
|
||||
struct_message_TEAMButton sendTEAMButtonDATA;
|
||||
|
||||
esp_now_peer_info_t peerInfo;
|
||||
|
||||
// callback when data is sent
|
||||
|
||||
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
|
||||
Serial.print("\r\nLast Packet Send Status:\t");
|
||||
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
// receive config
|
||||
// Structure example to send data
|
||||
// Must match the receiver structure
|
||||
typedef struct struct_message {
|
||||
bool buttonSTARTremote;
|
||||
bool buttonPAUSEremote;
|
||||
bool buttonPITremote;
|
||||
bool buttonRESETremote;
|
||||
bool buttonREDTEAMremote;
|
||||
bool buttonBLUETEAMremote;
|
||||
} struct_message;
|
||||
typedef struct struct_message_receive {
|
||||
bool buttonSTART;
|
||||
bool buttonPAUSE;
|
||||
bool buttonPIT;
|
||||
bool buttonRESET;
|
||||
bool buttonREDTEAM;
|
||||
bool buttonBLUETEAM;
|
||||
} struct_message_receive;
|
||||
|
||||
// Create a struct_message called remoteDATA
|
||||
struct_message remoteDATA;
|
||||
// Create a struct_message called receiveDATA
|
||||
struct_message_receive receiveDATA;
|
||||
|
||||
// callback function that will be executed when data is received
|
||||
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
|
||||
memcpy(&remoteDATA, incomingData, sizeof(remoteDATA));
|
||||
if (remoteDATA.buttonSTARTremote) {
|
||||
memcpy(&receiveDATA, incomingData, sizeof(receiveDATA));
|
||||
if (receiveDATA.buttonSTART) {
|
||||
buttonSTARTvar = true;
|
||||
}
|
||||
if (remoteDATA.buttonPAUSEremote) {
|
||||
if (receiveDATA.buttonPAUSE) {
|
||||
buttonPAUSEvar = true;
|
||||
}
|
||||
if (remoteDATA.buttonPITremote) {
|
||||
if (receiveDATA.buttonPIT) {
|
||||
buttonPITvar = true;
|
||||
}
|
||||
if (remoteDATA.buttonRESETremote) {
|
||||
if (receiveDATA.buttonRESET) {
|
||||
buttonRESETvar = true;
|
||||
}
|
||||
if (receiveDATA.buttonREDTEAM) {
|
||||
buttonREDTEAMvar = true;
|
||||
}
|
||||
if (receiveDATA.buttonBLUETEAM) {
|
||||
buttonBLUETEAMvar = true;
|
||||
}
|
||||
}
|
||||
|
||||
// send data to clock:
|
||||
void sendTimeDisplay(int MINUTES, int SECONDS, int RED, int GREEN, int BLUE, int BRIGHTNESS) {
|
||||
// only send data if there was a change
|
||||
if ((sendClockDATA.sendMinutes != MINUTES) || (sendClockDATA.sendSeconds != SECONDS) || (sendClockDATA.sendREDchannel != RED) || (sendClockDATA.sendGREENchannel != GREEN) || (sendClockDATA.sendBLUEchannel != BLUE) || (sendClockDATA.sendBrightness != BRIGHTNESS)) {
|
||||
sendClockDATA.sendMinutes = MINUTES;
|
||||
sendClockDATA.sendSeconds = SECONDS;
|
||||
sendClockDATA.sendREDchannel = RED;
|
||||
sendClockDATA.sendGREENchannel = GREEN;
|
||||
sendClockDATA.sendBLUEchannel = BLUE;
|
||||
sendClockDATA.sendBrightness = BRIGHTNESS;
|
||||
|
||||
esp_err_t result = esp_now_send(broadcastAddressClock, (uint8_t *) &sendClockDATA, sizeof(sendClockDATA));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// set outputs
|
||||
pinMode(RED_TEAM_LED_PIN, OUTPUT);
|
||||
pinMode(BLUE_TEAM_LED_PIN, OUTPUT);
|
||||
pinMode(PIT_RELEASE_PIN, OUTPUT);
|
||||
|
||||
digitalWrite(BLUE_TEAM_LED_PIN, LOW);
|
||||
digitalWrite(RED_TEAM_LED_PIN, LOW);
|
||||
digitalWrite(PIT_RELEASE_PIN, LOW);
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set device as a Wi-Fi Station
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
@@ -127,19 +161,35 @@ void setup() {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
// ESP Now send part:
|
||||
// Once ESPNow is successfully Init, we will register for Send CB to
|
||||
// get the status of Trasnmitted packet
|
||||
esp_now_register_send_cb(OnDataSent);
|
||||
|
||||
// Register peer
|
||||
memcpy(peerInfo.peer_addr, broadcastAddressClock, 6);
|
||||
peerInfo.channel = 0;
|
||||
peerInfo.encrypt = false;
|
||||
// Add peer
|
||||
if (esp_now_add_peer(&peerInfo) != ESP_OK){
|
||||
Serial.println("Failed to add peer");
|
||||
return;
|
||||
}
|
||||
|
||||
// set rumble stopwatch resolution to seconds
|
||||
|
||||
esp_err_t result = esp_now_send(broadcastAddressClock, (uint8_t *) &sendClockDATA, sizeof(sendClockDATA));
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// ESP Now receive part:
|
||||
// Once ESPNow is successfully Init, we will register for recv CB to
|
||||
// get recv packer info
|
||||
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
|
||||
|
||||
|
||||
// set rumble stopwatch resolution to seconds
|
||||
|
||||
// sanity check delay - allows reprogramming if accidently blowing power w/leds
|
||||
delay(2000);
|
||||
// This function sets up the leds and tells the controller about them
|
||||
FastLED.addLeds<WS2811Controller800Khz, LED_DATA_PIN_TIMER, GRB>(leds_TIMER, NUM_LEDS_TIMER); // GRB ordering is typical
|
||||
//FastLED.setMaxRefreshRate(10, true);
|
||||
FastLED.setMaxPowerInVoltsAndMilliamps(5,2000); // Limit to 10W of output power
|
||||
}
|
||||
|
||||
int XDAS = 255;
|
||||
@@ -198,10 +248,10 @@ void loop() {
|
||||
PITreleased = false;
|
||||
ESP.restart();
|
||||
}
|
||||
blink_LED_RedTeam(200);
|
||||
blink_LED_BlueTeam(200);
|
||||
//blink_LED_RedTeam(200);
|
||||
//blink_LED_BlueTeam(200);
|
||||
// update the LED Display
|
||||
showTimeDisplay((FightCountDown[0].remaining()/60%10), (FightCountDown[0].remaining()%60), 0, XDAS, 0);
|
||||
sendTimeDisplay((FightCountDown[0].remaining()/60%10), (FightCountDown[0].remaining()%60), 0, XDAS, 0, CLOCK_LED_BRIGHTNESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -212,6 +262,6 @@ void loop() {
|
||||
// deactivate solenoids if needed
|
||||
checkPIT();
|
||||
// update the LED Display
|
||||
showTimeDisplay(12, 34, XDAS, 0, XDAS);
|
||||
sendTimeDisplay(12, 34, XDAS, 0, XDAS, CLOCK_LED_BRIGHTNESS);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user