Please feel free to comment or revise this module for the PCF8574X
Thanks in advanced for all your comments and suggestions to make this module robust and complete to find it's way into the huge hall of modules ;-)
Looks good - would it be possible to tweak the names a little (and add a connect function) so it had a similar API to http://www.espruino.com/MCP23xxx - using read(pin) etc? It'd just be nice for users to be able to swap between different port expanders without changing code.
Also, if you were able to add fields for A0..A7 which themselves were instances of a class with read/write fields then you could actually pass them into quite a few other modules as if they were normal Pins.
For example digitalWrite(expander.A0, 1) would just magically work.
I agree with @Gordon here - port expanders are much more useful if they all have a consistent API and provided pin objects with read/write/set/reset/mode methods so they worked with the standard functions.
That sort of thing is one of the ways that Espruino is a lot more friendly than Arduino.
On a related note - is there a method of a pin object for analogRead/analogWrite? It doesn't look like there is - maybe there should be? It would be neat for those PWM-capable port expanders, and external ADC chips.... though maybe the complexities and limitations of those parts would make this less useful than it seems at first glance.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem