// ROFLS+ Referee Remote #include #include // automatically installed for ESP32 boards, I think? #include // automatically installed for ESP32 boards #include // https://github.com/avdwebLibraries/avdweb_Switch // Hardware connections #define START_BTN_PIN 4 #define PAUSE_BTN_PIN 3 #define PIT_BTN_PIN 2 #define RESET_BTN_PIN 1 // define buttons and switches Switch buttonSTART = Switch(START_BTN_PIN); Switch buttonPAUSE = Switch(PAUSE_BTN_PIN); Switch buttonPIT = Switch(PIT_BTN_PIN); Switch buttonRESET = Switch(RESET_BTN_PIN); bool buttonSTARTvar = false; bool buttonPAUSEvar = false; bool buttonPITvar = false; bool buttonRESETvar = false; bool sendDATA = false; // ESP-NOW config // REPLACE WITH YOUR RECEIVER MAC Address uint8_t broadcastAddress[] = {0x84, 0xFC, 0xE6, 0xC7, 0x1A, 0x8C}; // Structure example to send data // Must match the receiver structure typedef struct struct_message { bool buttonSTARTremote; bool buttonPAUSEremote; bool buttonPITremote; bool buttonRESETremote; } struct_message; // Create a struct_message called myData struct_message remoteDATA; 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"); } */ void setup() { Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // 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, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } } void loop() { // poll all the switch/button inputs pollInput(); // start button logic if (buttonSTARTvar) { buttonSTARTvar = false; remoteDATA.buttonSTARTremote = true; sendDATA = true; } // pause button logic if (buttonPAUSEvar) { buttonPAUSEvar = false; remoteDATA.buttonPAUSEremote = true; sendDATA = true; } // pit button logic if (buttonPITvar) { buttonPITvar = false; remoteDATA.buttonPITremote = true; sendDATA = true; } // reset button logic if (buttonRESETvar) { buttonRESETvar = false; remoteDATA.buttonRESETremote = true; sendDATA = true; } // Set values to send //remoteDATA.buttonSTARTremote = false; //remoteDATA.buttonPAUSEremote = false; //remoteDATA.buttonPITremote = false; //remoteDATA.buttonRESETremote = false; // Send message via ESP-NOW //esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &remoteDATA, sizeof(remoteDATA)); if (sendDATA == true) { esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &remoteDATA, sizeof(remoteDATA)); sendDATA = false; // clear remoteDATA struct remoteDATA.buttonSTARTremote = false; remoteDATA.buttonPAUSEremote = false; remoteDATA.buttonPITremote = false; remoteDATA.buttonRESETremote = false; if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } } /* if (result == ESP_OK) { Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); } */ //delay(2000); }