Hi,
I’ve an 8 relay board and I’d like to read the status of the chip’s pins to know whether the relays have received or not the signal. For that I’m using the WidgetLed and, because there’re 8 of them, I thought initialize them in a loop but I just cannot get it right. Can it be actually done?
This’ the error I get: “variable-sized object ‘ledR’ may not be initialized”
//......
const int ledR[] = {1, 2, 3, 4, 5, 6, 7, 8}; //relay number
const int V[] = {12, 13, 14, 15, 16, 17, 18, 19}; //virtual pins
//WidgetLED ledR1(V12);
//WidgetLED ledR2(V13);
//WidgetLED ledR3(V14);
//WidgetLED ledR4(V15);
//WidgetLED ledR5(V16);
//WidgetLED ledR6(V17);
//WidgetLED ledR7(V18);
//WidgetLED ledR8(V19);
void initLedWidgets() {
//init led widgets
for (int i = 0; i < 8; i++) {
WidgetLED ledR[i](V[i]);
}
}
void setup(){
//......
initLedWidgets();
//get relays status to turn leds on/off
timer.setInterval(2000L, leds);
//......
}
void leds() {
for (int x = 0; x < 8; x++) {
bool pinState = (digitalRead(R[x]) == LOW); //EDIT: R = relay pin number
//if signal is 0, turn off LEDx
if (pinState) {
ledR[x].off();
}
//if signal is 1, turn on LEDx
else {
ledR[x].on();
}
}
}