//
// FILE: PCF8575_array.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-12-13
// PUPROSE: demo array of PCF - not tested
#include "PCF8575.h"
// adjust addresses if needed
PCF8575 A(0x22);
// PCF8575 B(0x39);
// PCF8575 C(0x3A);
// PCF8575 PCF = { A };
PCF8575 PCF(0x22);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCF8575_LIB_VERSION:\t");
// Serial.println(PCF8575_LIB_VERSION);
int i = 0;
// for (int i = 0; i < 3; i++)
// {
PCF.begin();
// }
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
scan_i2c();
}
void loop()
{
int i = 0;
Serial.print("HIGH ");
for (uint8_t port = 0; port < 16; port++)
{
Serial.print(port);
Serial.print(" ");
PCF.digitalWrite(port, HIGH);
delay(200);
}
Serial.println();
delay(1000);
// for (int i = 0; i < 3; i++)
// {
Serial.print("LOW ");
for (uint8_t port = 0; port < 16; port++)
{
Serial.print(port);
Serial.print(" ");
PCF.digitalWrite(port, LOW);
delay(200);
}
Serial.println();
Serial.println();
// }
delay(2000);
}
// void setup() {
// Wire.begin();
// Serial.begin(9600);
// Serial.println("\nI2C Scanner");
// }
void scan_i2c() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++) {
// The i2c-scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4) {
Serial.print("Unknown error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
delay(2000); // wait 5 seconds for next scan
}
// -- END OF FILE --
// //
// // FILE: pcf8575_test2.ino
// // AUTHOR: Rob Tillaart
// // DATE: 2021-01-03
// // PUPROSE: demo rotateLeft, -Right and toggleMask
// #include "PCF8575.h"
// // adjust addresses if needed
// PCF8575 PCF(0x20); // add LEDs to lines (used as output)
// void setup()
// {
// Serial.begin(115200);
// Serial.println(__FILE__);
// Serial.print("PCF8575_LIB_VERSION:\t");
// Serial.println(PCF8575_LIB_VERSION);
// PCF.begin();
// for(int pin = 0; pin < 16; pin++) {
// PCF.write(pin, LOW);
// };
// for (int i = 0; i < 15; i++)
// {
// PCF.write(i, 1);
// Serial.println(i);
// delay(1000);
// }
// // PCF.write(7, 1);
// // PCF.write(6, 1);
// Serial.println("");
// Serial.println("rotateLeft");
// for (int i = 0; i < 15; i++)
// {
// PCF.rotateLeft();
// Serial.println(i);
// delay(1000);
// }
// Serial.println("");
// Serial.println("rotateRight");
// for (int i = 0; i < 15; i++)
// {
// PCF.rotateRight();
// Serial.println(i);
// delay(1000);
// }
// Serial.println("");
// Serial.println("rotateLeft3");
// for (int i = 0; i < 15; i++)
// {
// PCF.rotateLeft(3);
// Serial.println(i);
// delay(1000);
// }
// Serial.println("");
// Serial.println("rotateRight2");
// for (int i = 0; i < 15; i++)
// {
// PCF.rotateRight(2);
// Serial.println(i);
// delay(1000);
// }
// Serial.println("");
// Serial.println("toggleMask");
// for (uint16_t i = 0; i < 65535; i += 253)
// {
// PCF.toggleMask(i);
// Serial.println(i);
// delay(200);
// }
// Serial.println("");
// Serial.println("Last");
// // 0010 0111 -> 0x27
// // 1110 0100
// PCF.write16(0x2755);
// for (int i = 0; i < 255; i++)
// {
// PCF.reverse();
// Serial.println(i);
// delay(200);
// }
// }
// void loop()
// {
// }
// // -- END OF FILE --
// #include "Arduino.h"
// #include <PCF8575.h>
// #include <Wire.h>
// PCF8575 pcf20(0x20);
// // TwoWire *_wire;
// // // Instantiate Wire for generic use at 400kHz
// // TwoWire I2Cone = TwoWire(0);
// // // Instantiate Wire for generic use at 100kHz
// // TwoWire I2Ctwo = TwoWire(1);
// // void setup()
// // {
// // Serial.begin(9600);
// // // Set pinMode to OUTPUT
// // for(int i=0;i<16;i++) {
// // pcf8575.pinMode(i, OUTPUT);
// // }
// // for(int i=0;i<16;i++) {
// // pcf8575.digitalWrite(i, HIGH);
// // }
// // pcf8575.begin();
// // }
// static int pin = 0;
// // void loop()
// // {
// // // pcf20.write(pin, LOW);
// // // delay(1000);
// // // pcf20.write(pin, HIGH);
// // // pcf20.write16(pin);
// // // Serial.println(pin);
// // // delay(1000);
// // // pin++;
// // // if (pin > 15) pin = 0;
// // Serial.println("테스트");
// // for (uint16_t i = 0; i < 16; i++) {
// // pcf20.write(i, HIGH);
// // // pcf20.write(i, LOW);
// // }
// // for (uint16_t i = 0; i < 1024; i++) {
// // pcf20.write(i, 1);
// // uint16_t value = pcf20.read16();
// // Serial.println(i);
// // // Serial.print(", 0x20 after read: ");
// // // Serial.println(value, HEX);
// // // Serial.println(value);
// // delay(1000);
// // }
// // delay(1000);
// // Serial.println("순서적");
// // for (uint16_t i = 0; i < 1024; i++) {
// // pcf20.write16(i);
// // uint16_t value = pcf20.read16();
// // Serial.print(i);
// // Serial.print(", 0x20 after read: ");
// // // Serial.println(value, HEX);
// // Serial.println(value);
// // delay(100);
// // }
// // delay(1000);
// // }
// void setup() {
// Serial.begin(115200);
// Serial.print("PCF8575_LIB_VERSION:\t");
// Serial.println(PCF8575_LIB_VERSION);
// if (!pcf20.begin()) {
// Serial.println("Chip not responding.");
// }
// if (!pcf20.isConnected()) {
// Serial.println("could not initialize... => not connected");
// while (1);
// }
// uint16_t value = pcf20.read16();
// Serial.print("0x20 1st read: ");
// // Serial.println(value, HEX);
// Serial.println(value);
// for(int pin = 0; pin < 16; pin++) {
// pcf20.write(pin, LOW);
// };
// }
// void loop() {
// Serial.println("순서적");
// for (uint16_t i = 0; i < 256; i++) {
// pcf20.write16(i);
// uint16_t value = pcf20.read16();
// Serial.print(i);
// Serial.print(", 0x20 after read: ");
// // Serial.println(value, HEX);
// Serial.println(value);
// delay(1000);
// }
// delay(1000);
// pcf20.write(0, 1);
// delay(1000);
// Serial.println("shiftLeft");
// for (int i = 0; i < 8; i++) {
// pcf20.shiftLeft();
// delay(20);
// }
// delay(1000);
// Serial.println("shiftRight");
// for (int i = 0; i < 8; i++) {
// pcf20.shiftRight();
// delay(20);
// }
// delay(1000);
// Serial.println("OnOff");
// for (int i = 0; i < 9; i++) {
// pcf20.write(i, 1);
// delay(20);
// pcf20.write(i, 0);
// delay(20);
// }
// delay(1000);
// Serial.println("toggle");
// for (int i = 0; i < 9; i++) {
// pcf20.toggle(i);
// delay(20);
// pcf20.toggle(i);
// delay(20);
// }
// delay(1000);
// Serial.println("Echo the state");
// // Echo the state of the lines on the other PCF
// uint16_t value = pcf20.read16();
// pcf20.write16(value);
// delay(20);
// delay(1000);
// }