//
// FILE: pcf8575_test2.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo rotateLeft, -Right and toggleMask
// URL: https://github.com/RobTillaart/PCF8575
// addresses: 0x20 = 000
// 0x27 = 111
// 27/5/24: One PCF module working with 16 LEDs. Address are all low at 0x20.
// 29/5/24: module working, address changed to 111 0x27.
// can write to a single output - as per PCF and PCF 1 below.
// tested successfully - can control single outputs on individual expanders
#include "PCF8575.h"
// adjust addresses if needed
//PCF8575 PCF(0x21); // add LEDs to lines (used as output)
PCF8575 PCF(0x21); // address 0/0/0
// RP: does adding PCF8575 PCF1(0x22); give access to extra expander modules? 22/5/24
PCF8575 PCF1(0x20); // 1/1/1/
void setup()
{
Serial.begin(115200);
Serial.println("Hello, ESP32!");
bool tmpArr[8] = {1,1,1,1,0,0,0,0};
byte tmpByte = boolArrayToByte(tmpArr,true);
Serial.println(combineBytes(tmpByte,0x00),BIN);
// Serial.println(PCF8575_LIB_VERSION);
Wire.begin();
PCF.begin(); // RP
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// 0010 0111 -> 0x27
// 1110 0100
}
void loop()
{
uint16_t fbOut = 0xFFFF;
PCF.write(13,1);
PCF.write16(fbOut);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
uint16_t combineBytes(byte highByte, byte lowByte) { return (uint16_t(highByte) << 8) | uint16_t(lowByte); }
byte boolArrayToByte(bool arr[8], bool MSB_first) {
byte result = 0;
if (MSB_first) { for (int i = 0; i < 8; i++) { result |= (arr[i] << (7 - i)); } } // MSB first (arr[0] = MSB)
else { for (int i = 0; i < 8; i++) { result |= (arr[i] << i); } } // MSB last (arr[7] = MSB)
return result;
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
chip1:nINT
chip1:A1
chip1:A2
chip1:P00
chip1:P01
chip1:P02
chip1:P03
chip1:P04
chip1:P05
chip1:P06
chip1:P07
chip1:GND
chip1:P10
chip1:P11
chip1:P12
chip1:P13
chip1:P14
chip1:P15
chip1:P16
chip1:P17
chip1:A0
chip1:SCL
chip1:SDA
chip1:VCC
chip2:nINT
chip2:A1
chip2:A2
chip2:P00
chip2:P01
chip2:P02
chip2:P03
chip2:P04
chip2:P05
chip2:P06
chip2:P07
chip2:GND
chip2:P10
chip2:P11
chip2:P12
chip2:P13
chip2:P14
chip2:P15
chip2:P16
chip2:P17
chip2:A0
chip2:SCL
chip2:SDA
chip2:VCC
vcc1:VCC
vcc2:VCC
gnd1:GND
gnd2:GND
gnd3:GND
sw1:1
sw1:2
sw1:3
sw2:1
sw2:2
sw2:3
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
led5:A
led5:C
led6:A
led6:C
led7:A
led7:C
led8:A
led8:C
led9:A
led9:C
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
r8:1
r8:2
r9:1
r9:2
vcc3:VCC
led10:A
led10:C
led11:A
led11:C
led12:A
led12:C
led13:A
led13:C
led14:A
led14:C
led15:A
led15:C
led16:A
led16:C
led17:A
led17:C
r10:1
r10:2
r11:1
r11:2
r12:1
r12:2
r13:1
r13:2
r14:1
r14:2
r15:1
r15:2
r16:1
r16:2
r17:1
r17:2
sw3:1
sw3:2
sw3:3