Naming & addressing PCF8574 port expanders

Apologies if the answer to this is extremely simple. I think I've actually found a work around for this but thought it might be worth asking if not.

I have a PCF8574 I2C port expander (or three) connected to an esp8266.

I can correctly communicate with them fine using digital writes; I can selectively switch pins high / low on all three separate expanders (so the I2C communication is working fine).

I've assigned names to them. For instance;

PCF8574 expander1(0x20, D2, D1);


So I can just call, as an example;

expander1.digitalWrite(P0, HIGH)

To switch pin 0 of the port expander at 0x20 on the I2C bus on.

The problem I was having was that I was trying to switch the pins on the PCF8574's on / off using a timer; this timer (Arduino Playground - Timer Library). Because I wanted to be able to switch those pins high / low for prolonged periods of time in the background whilst the loop continues.

In the timer example, Simon names his time 't'. In the loop he calls 't.update', which seems simple enough.

What I was having problems with, trying to use the timer, is the that the name of the pins on the port expander.

Say for instance if it's switching a single normal pin on and off, Simon defines that in the setup by using the pulse function, so he has in the setup;

t.pulse(pin, 10 * 60 * 1000, HIGH); // 10 minutes

That seems straightforward; when the loop calls 't.update', if it's not already doing the pulse it'll initiate it.

But I can't figure out how to address P0, for example, on 'expander1'; e.g.

expander1.t.pulse(P0, 1000, HIGH)

Will produce an error. As will;

t.pulse(expander1.P0, 1000, HIGH)

I've tried a few other combinations but can't figure it out.

Thanks for reading.

What would the correct syntax for that be?

You can’t use any of those timer functions which take a pin number as a parameter because that will assume an Arduino pin number and not an expander pin number.
You can, however, use say the “every” method which specifies a call back routine, then in the call back routine, explicitly set the expander pin.