added preliminary implementation of Team Button LEDs
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
const bool writeBoardID = false;
|
||||
int boardID = 0;
|
||||
|
||||
|
||||
// Hardware connections
|
||||
#define START_BTN_PIN 10
|
||||
#define PAUSE_BTN_PIN 8
|
||||
@@ -67,6 +66,14 @@ typedef struct struct_message_send {
|
||||
// Create a struct_message called myData
|
||||
struct_message_send sendDATA;
|
||||
|
||||
// Add struct for receiving ESP-NOW data
|
||||
typedef struct struct_message_receive {
|
||||
bool TEAMLED; // Boolean to control the team LED
|
||||
} struct_message_receive;
|
||||
|
||||
// Create instance for receiving ESP-NOW data
|
||||
struct_message_receive receiveDATA;
|
||||
|
||||
esp_now_peer_info_t peerInfo;
|
||||
|
||||
Preferences preferences;
|
||||
@@ -77,6 +84,16 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
|
||||
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
|
||||
}
|
||||
|
||||
// Callback function for receiving ESP-NOW data
|
||||
void OnDataReceive(const esp_now_recv_info *recv_info, const uint8_t *incomingData, int len) {
|
||||
// Copy the received data into the struct
|
||||
memcpy(&receiveDATA, incomingData, sizeof(receiveDATA));
|
||||
|
||||
// Update the LED state based on received data
|
||||
digitalWrite(TEAM_LED_PIN, receiveDATA.TEAMLED ? HIGH : LOW);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@@ -119,6 +136,9 @@ void setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Register receive callback
|
||||
esp_now_register_recv_cb(OnDataReceive);
|
||||
|
||||
// populate sendDATA struct with some data:
|
||||
sendDATA.boardID = boardID;
|
||||
sendDATA.buttonSTART = false;
|
||||
|
||||
Reference in New Issue
Block a user