So, there is my whole sketch with MySensors. I have a problem with PCF8574 addresses array. IDE says: could not convert '{32, 33, 34, 35, 36, 37, 38, 39}' from brace-enclosed initializer list>' to 'PCF8574' in this line:
PCF8574 expa = {0x20, 0x21, 0x22, 0x23,0x24, 0x25, 0x26, 0x27};// expanders addresses
#define MY_DEBUG
#define MY_GATEWAY_SERIAL
#if F_CPU == 8000000L
#define MY_BAUD_RATE 38400
#endif
#define MY_INCLUSION_MODE_FEATURE
#define MY_INCLUSION_BUTTON_FEATURE
#define MY_INCLUSION_MODE_DURATION 60
#define MY_INCLUSION_MODE_BUTTON_PIN 3
#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <SimpleTimer.h>
#include <PCF8574.h> // i/o expander ic library
#define RELAY_ON 0 // switch around for realy HIGH/LOW state
#define RELAY_OFF 1
#define MY_REPEATER_FEATURE
#define noRelays 1 // number of relays
const int buttonPin[] = {3}; // input button pins
PCF8574 expa = {0x20, 0x21, 0x22, 0x23,0x24, 0x25, 0x26, 0x27};// expanders addresses
const byte expaCount = sizeof expa/ sizeof expa[0];
class Relays {
public:
int buttonPin;
//int relayPin;
byte oldValue;
boolean relayState;
};
SimpleTimer timer;
Relays Relay[noRelays];
Bounce debouncer[noRelays];
MyMessage msg[noRelays];
void setup() {
delay(250);
sendSketchInfo("My Switch Relay PCF8574", "1.0"); //MySensors Device Info
delay(250);
// For each port extender
for (byte p = 0; p < expaCount; p++) {
// Set all 8 pins on the port extender to OUTPUT
for (byte i = 0; i < 8; i++) {
expa[p].pinMode(i, OUTPUT);
}
//start the communication with the ic's
expa[p].begin();
}
for (int i = 0; i < noRelays; i++) {
Relay[i].buttonPin = buttonPin[i];
msg[i].sensor = i; // initialize messages
msg[i].type = V_LIGHT;
debouncer[i] = Bounce(); // initialize debouncer
debouncer[i].attach(buttonPin[i]);
debouncer[i].interval(5);
pinMode(Relay[i].buttonPin, INPUT_PULLUP);
Relay[i].relayState = loadState(i);
send(msg[i].set(Relay[i].relayState? true : false) ); // make controller aware of last status
present(i, S_LIGHT); // present sensor to gateway
delay(250);
}
for (int i = 0, int j = 0, k = 0; i < noRelays; i++, k++) {
if (k > 8) {j++; k = 0;}
if (Relay.relayState[i] = 0){
expa[j].digitalWrite(k, LOW);
}
if (Relay.relayState[i] = 1){
expa[j].digitalWrite(k, HIGH);
}
}
}
void loop() {
for (int i = 0, int j = 0, k = 0; i < noRelays; i++, k++) {
if (k > 8) {j++; k = 0;}
if(debouncer[i].update()){
byte value = debouncer[i].read();
if(value == 0){
Relay[i].relayState = !Relay[i].relayState;
send(msg[i].set(Relay[i].relayState? true : false) );
serial.println(Relay[i].relayState);
saveState(i, Relay[i].relayState);
}
}
if (Relay.relayState[i] = 0){
expa[j].digitalWrite(k, LOW);
}
if (Relay.relayState[i] = 1){
expa[j].digitalWrite(k, HIGH);
}
}
}
// process incoming message
void receive(const MyMessage &message){
if (message.type == V_LIGHT){
Relay[message.sensor].relayState = message.getBool();
//digitalWrite(Relay[message.sensor].relayPin, LOW); // and set relays accordingly
saveState( message.sensor, Relay[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)
//timer.setTimeout(500L, off);
}
}
// void off(){
// digitalWrite(Relay[message.sensor].relayPin, HIGH);
// }