Code:
#include "Arduino.h"
#include "PCF8574.h"
// Set i2c address
PCF8574 pcf8574(0x27,4,5); //4 is SDA 5 is SCL need replace by your board's pin define
/*
A0 A1 A2
0 0 0 =0x20
0 0 1 =0x21
0 1 0 =0x22
0 1 1 =0x23
1 0 0 =0x24
1 0 1 =0x25
1 1 0 =0x26
1 1 1 =0x27
*/
void setup()
{
Serial.begin(115200);
// delay(1000);
// Set pinMode to OUTPUT
pcf8574.pinMode(P0, OUTPUT);
pcf8574.pinMode(P1, OUTPUT);
pcf8574.pinMode(P2, OUTPUT);
pcf8574.pinMode(P3, OUTPUT);
pcf8574.pinMode(P4, OUTPUT);
pcf8574.pinMode(P5, OUTPUT);
pcf8574.pinMode(P6, OUTPUT);
pcf8574.pinMode(P7, OUTPUT);
// pcf8574.pinMode(P1, INPUT);
Serial.print("Init pcf8574...");
if (pcf8574.begin()){
Serial.println("OK");
}else{
Serial.println("KO");
}
}
void loop()
{
pcf8574.digitalWrite(P0, HIGH);
delay(300);
pcf8574.digitalWrite(P0, LOW);
delay(300);
}
DO8.zip (Size: 485 bytes / Downloads: 156)
PCF8574 arduino library ZIP file download:
PCF8574_library.zip (Size: 23.8 MB / Downloads: 158)