Can't figure out how to pass the array number as parameter to the predefined receivedData() function of the Yet_Another_Arduino_Wiegand_Library-2.0.0. The following code compiles w/o issues:
#include <Wiegand.h>
Wiegand WG[5];
void setup() {
WG[0].onReceive(receivedData, "0");
WG[1].onReceive(receivedData, "1");
WG[2].onReceive(receivedData, "2");
WG[3].onReceive(receivedData, "3");
WG[4].onReceive(receivedData, "4");
for(byte r = 0; r < 5; r++) {
WG[r].begin(Wiegand::LENGTH_ANY, true);
}
}
void loop() {
// no need to loop in this example
}
void receivedData(uint8_t* data, uint8_t bits, const char* message) {
// do whatever with the received data
}
I have tried a ton of different ways to convert the 'r' variable into char array, but any permutation of the following code is doomed to a compilation error:
#include <Wiegand.h>
Wiegand WG[5];
void setup() {
for(byte r = 0; r < 5; r++) {
String str = String(r);
WG[r].onReceive(receivedData, str.charAt(0));
WG[r].begin(Wiegand::LENGTH_ANY, true);
}
}
void loop() {
// no need to loop in this example
}
void receivedData(uint8_t* data, uint8_t bits, const char* message) {
// do whatever with the received data
}
I'm compiling for the ESP32 with Arduino IDE 1.8.16 if it makes any difference.
Any help will be greatly appreciated!
@johnwasser, thanks for your remark, I have indeed omitted all parts of the code that are not directly related to the problem I'm having. I'm using interrupts and in my experience the ESP32 works fine with up to 10 wiegand readers simultaneously, though as you mentioned at that point there are hardly any pins left for other tasks. 5 readers and 5 relays is just about the sweet spot.
D0 pins: 13, 15, 17, 19, 25
D1 pins: 14, 16, 18, 23, 34
Relay pins: 12, 32, 26, 27, 33
An alternative to using the "char *" argument to determine which of the interfaces received the input: define a separate "receivedData()" function for each device.