//
// 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;
}