diff --git a/OurSketch.ino b/OurSketch.ino index f9de4ce..e77698f 100644 --- a/OurSketch.ino +++ b/OurSketch.ino @@ -1,4 +1,6 @@ #include +#include +#include #include // --- 色定義 --- @@ -43,6 +45,8 @@ } + + void resetBlocks() { for (int i = 0; i < BLOCK_ROWS; ++i) for (int j = 0; j < BLOCK_COLS; ++j) @@ -215,4 +219,33 @@ delay(16); } - \ No newline at end of file + + +void Init_ESPNOW() +{ // ESPNowの初期化 + // 引用: https://101010.fun/iot/esp32-m5stickc-plus-esp-now.html + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + if (esp_now_init() == ESP_OK) + { + M5.Display.println("ESP-Now Init Success"); + } + else + { + M5.Display.println("ESP-Now Init failed"); + } + // マルチキャスト用Slave登録 + memset(&peerInfo, 0, sizeof(peerInfo)); + for (int i = 0; i < 6; ++i) + { + peerInfo.peer_addr[i] = (uint8_t)0xff; + } + esp_err_t addStatus = esp_now_add_peer(&peerInfo); + if (addStatus == ESP_OK) + { + // Pair success + M5.Display.println("Pair success"); + esp_now_register_send_cb(onESPNOWSent); //送信後のコールバック関数を指定する + esp_now_register_recv_cb(onESPNOWReceive); ///受信時のコールバック関数を指定する + } +} \ No newline at end of file