-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathespnowreceiver2.ino
64 lines (49 loc) · 1.49 KB
/
espnowreceiver2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <Adafruit_NeoPixel.h>
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp-now-esp32-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <esp_now.h>
#include <WiFi.h>
Adafruit_NeoPixel pixels(1, 21, NEO_GRB + NEO_KHZ800);
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
int a;
int b;
} struct_message;
// Create a struct_message called myData
struct_message myData;
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
pixels.fill(0x008000);
pixels.show();
tone(38, myData.a, (myData.b * 0.7));
delay(myData.b);
pixels.fill(0x000000);
pixels.show();
noTone(38);
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
pixels.begin();
pixels.setBrightness(100);
// 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 recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
}