#include #include #define BUTTON_PIN 20 // Change to the pin your button is connected to uint8_t receiverMac[] = {0x10, 0x20, 0xba, 0x76, 0xe1, 0xec}; // Replace with your S3 MAC typedef struct { int angle; } Message; Message outgoingData; bool lastBtn = HIGH; int currentAngle = 0; void onSent(const wifi_tx_info_t *info, esp_now_send_status_t status) { Serial.print("Send status: "); Serial.println(status == ESP_NOW_SEND_SUCCESS ? "OK" : "FAIL"); } void setup() { Serial.begin(115200); pinMode(BUTTON_PIN, INPUT_PULLUP); // use internal pull-up resistor WiFi.mode(WIFI_STA); if (esp_now_init() != ESP_OK) { Serial.println("ESP-NOW init failed"); return; } esp_now_register_send_cb(onSent); esp_now_peer_info_t peer = {}; memcpy(peer.peer_addr, receiverMac, 6); peer.channel = 0; peer.encrypt = false; if (esp_now_add_peer(&peer) != ESP_OK) { Serial.println("Failed to add peer"); return; } Serial.println("C3 Sender ready"); } void loop() { bool btn = digitalRead(BUTTON_PIN); // Detect button press (falling edge) if (btn == LOW && lastBtn == HIGH) { delay(50); // simple debounce // Toggle angle currentAngle = (currentAngle == 0) ? 90 : 0; outgoingData.angle = currentAngle; Serial.print("Button pressed → sending angle: "); Serial.println(currentAngle); esp_now_send(receiverMac, (uint8_t*)&outgoingData, sizeof(outgoingData)); delay(1000); // to avoid double measurements } lastBtn = btn; }