Here's a library for the PCF8574 in case anybody wants it. This works in v1.00 - if anybody wants to alter it for v1.01 please do so.
The .h file >
// pcf8574 lib by william lewis
#ifndef PCF8574_h
#define PCF8574_h
#include <inttypes.h>
class PCF8574Class
{
public:
void Prox(int, int, int);
void Set(int, int);
private:
int read(int);
void write(int, int);
};
extern PCF8574Class PCF8574;
#endif
The .cpp file >>
// pcf8574 lib by william lewis
#include <Wire.h>
#include "PCF8574.h"
static int current_data;
static int state;
int pin_array[2][8] = {
0B01111111, 0B10111111, 0B11011111, 0B11101111, 0B11110111, 0B11111011, 0B11111101, 0B11111110,
0B10000000, 0B01000000, 0B00100000, 0B00010000, 0B00001000, 0B00000100, 0B00000010, 0B00000001
};
void PCF8574Class::Prox(int addr, int pin, int x) {
state = PCF8574.read(addr);
if (x == 1)
state &= pin_array[0][pin];
else if (x == 0)
state |= pin_array[1][pin];
PCF8574.write(addr, state); // ON
}
void PCF8574Class::Set(int addr, int bits){
write(addr, bits);
}
int PCF8574Class::read(int addr) {
Wire.requestFrom(addr, 1);
if (Wire.available()) {
return Wire.read();
}
}
void PCF8574Class::write(int addr, int data) {
current_data = data;
Wire.beginTransmission(addr);
Wire.write(data);
Wire.endTransmission();
}
PCF8574Class PCF8574;
The .pde >>>
#include "PCF8574.h"
#define EXPANDER_A B00100000 //0x20 //PCF8574
#define EXPANDER_B B00100001 //0x21 //PCF8574
void setup() {
PCF8574.Set(EXPANDER_B, 0x7F);
void loop(){
PCF8574.Prox(EXPANDER_B, 1, 1); //this turns ON bit 1 on your secondary expander B
PCF8574.Prox(EXPANDER_B, 1, 0); //this turns OFF bit 1 on your secondary expander B
PCF8574.Prox(EXPANDER_A, 1, 1); //this turns ON bit 1 on your primary expander A
PCF8574.Prox(EXPANDER_A, 1, 0); //this turns OFF bit 1 on your primary expander A
}