Skip to content

Commit

Permalink
update library.json, license, minor edits (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart authored Dec 23, 2021
1 parent c53c0c1 commit a2131cf
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 43 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 Rob Tillaart
Copyright (c) 2020-2022 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 9 additions & 7 deletions PCF8575.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: PCF8575.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-07-20
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8575
//
Expand All @@ -15,6 +15,7 @@
// 0.1.2 2021-07-09 fix #10 add set/getAddress() function
// 0.1.3 2021-12-01 update build-CI, readme
// add getButtonMask()
// 0.1.4 2021-12-23 update library.json, license, minor edits


#include "PCF8575.h"
Expand All @@ -32,7 +33,7 @@ PCF8575::PCF8575(const uint8_t deviceAddress, TwoWire *wire)


#if defined (ESP8266) || defined(ESP32)
bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t val)
bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t value)
{
_wire = &Wire;
if ((dataPin < 255) && (clockPin < 255))
Expand All @@ -42,17 +43,17 @@ bool PCF8575::begin(uint8_t dataPin, uint8_t clockPin, uint16_t val)
_wire->begin();
}
if (! isConnected()) return false;
PCF8575::write16(val);
PCF8575::write16(value);
return true;
}
#endif


bool PCF8575::begin(uint16_t val)
bool PCF8575::begin(uint16_t value)
{
_wire->begin();
if (! isConnected()) return false;
PCF8575::write16(val);
PCF8575::write16(value);
return true;
}

Expand Down Expand Up @@ -152,7 +153,7 @@ void PCF8575::toggleMask(const uint16_t mask)
void PCF8575::shiftRight(const uint8_t n)
{
if ((n == 0) || (_dataOut == 0)) return;
if (n > 15) _dataOut = 0; // shift 8++ clears all, valid...
if (n > 15) _dataOut = 0; // shift 15++ clears all, valid...
if (_dataOut != 0) _dataOut >>= n; // only shift if there are bits set
PCF8575::write16(_dataOut);
}
Expand All @@ -161,7 +162,7 @@ void PCF8575::shiftRight(const uint8_t n)
void PCF8575::shiftLeft(const uint8_t n)
{
if ((n == 0) || (_dataOut == 0)) return;
if (n > 15) _dataOut = 0; // shift 8++ clears all, valid...
if (n > 15) _dataOut = 0; // shift 15++ clears all, valid...
if (_dataOut != 0) _dataOut <<= n; // only shift if there are bits set
PCF8575::write16(_dataOut);
}
Expand Down Expand Up @@ -229,3 +230,4 @@ uint8_t PCF8575::readButton(const uint8_t pin)


// -- END OF FILE --

11 changes: 6 additions & 5 deletions PCF8575.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// FILE: PCF8575.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-20
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8575
//
Expand All @@ -16,7 +16,7 @@
#include "Wire.h"


#define PCF8575_LIB_VERSION (F("0.1.3"))
#define PCF8575_LIB_VERSION (F("0.1.4"))


#ifndef PCF8575_INITIAL_VALUE
Expand All @@ -32,12 +32,12 @@ class PCF8575
{
public:
// deviceAddress base = 0x20 + depends on address bits
explicit PCF8575(const uint8_t deviceAddress, TwoWire *wire = &Wire);
explicit PCF8575(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl, uint16_t val = PCF8575_INITIAL_VALUE);
bool begin(uint8_t sda, uint8_t scl, uint16_t value = PCF8575_INITIAL_VALUE);
#endif
bool begin(uint16_t val = PCF8575_INITIAL_VALUE);
bool begin(uint16_t value = PCF8575_INITIAL_VALUE);
bool isConnected();


Expand Down Expand Up @@ -90,3 +90,4 @@ class PCF8575


// -- END OF FILE --

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ the include of "pcf8575.h" to overrule the default value used with the

### Constructor

- **PCF8575(uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor with I2C device address,
and optional the Wire interface as parameter.
- **bool begin(uint8_t val = PCF8575_INITIAL_VALUE)** set the initial value for the pins and masks.
- **bool begin(uint8_t sda, uint8_t scl, uint8_t val = PCF8575_INITIAL_VALUE)** idem,
- **PCF8575(uint8_t deviceAddress = 0x20, TwoWire \*wire = &Wire)** Constructor with the optional
I2C device address, default 0x20, and the optional Wire interface as parameter.
- **bool begin(uint8_t value = PCF8575_INITIAL_VALUE)** set the initial value for the pins and masks.
- **bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t value = PCF8575_INITIAL_VALUE)** idem,
for the ESP32 where one can choose the I2C pins.
- **bool isConnected()** checks if the address is visible on the I2C bus.
- **bool setAddress(const uint8_t deviceAddress)** sets the device address after construction.
Expand Down Expand Up @@ -132,3 +132,5 @@ See examples.

- update documentation.
- keep in sync with pcf8574 (as far as meaningful)
- **value()** => **lastRead16()** ??

12 changes: 9 additions & 3 deletions examples/PCF8575_Wire2/PCF8575_Wire2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// FILE: PCF8575_Wire2.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-01-03
//
// PUPROSE: demo
//
// PUPROSE: demo


#include "PCF8575.h"

// adjust addresses if needed
PCF8575 PCF(0x39, &Wire2);


void setup()
{
Serial.begin(115200);
Expand All @@ -34,6 +34,7 @@ void setup()
delay(1000);
}


void loop()
{
Serial.println("HLT");
Expand All @@ -46,6 +47,7 @@ void loop()
}
}


void doHigh()
{
PCF.write(4, HIGH);
Expand All @@ -54,6 +56,7 @@ void doHigh()
Serial.println(x, HEX);
}


void doLow()
{
PCF.write(4, LOW);
Expand All @@ -62,6 +65,7 @@ void doLow()
Serial.println(x, HEX);
}


void doToggle()
{
PCF.toggle(4);
Expand All @@ -70,4 +74,6 @@ void doToggle()
Serial.println(x, HEX);
}


// -- END OF FILE --

4 changes: 3 additions & 1 deletion examples/PCF8575_array/PCF8575_array.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// AUTHOR: Rob Tillaart
// DATE: 2021-12-13
// PUPROSE: demo array of PCF - not tested
//


#include "PCF8575.h"

Expand All @@ -28,6 +28,7 @@ void setup()
}
}


void loop()
{
for (int i = 0; i < 3; i++)
Expand All @@ -52,3 +53,4 @@ void loop()


// -- END OF FILE --

14 changes: 9 additions & 5 deletions examples/PCF8575_interrupt/PCF8575_interrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
// DATE: 2021-01-03
// PUPROSE: test PCF8575 library
//

// TEST SETUP
// Connect INT pin of the PCF8575 to UNO pin 2
// Connect INT pin of the PCF8575 to UNO pin 2
//
// (from figure 4 datasheet
// Place a pull up resistor 4K7 between pin and 5V
// Place a capacitor 10-400pF between pin and GND
// (from figure 4 datasheet
// Place a pull up resistor 4K7 between pin and 5V
// Place a capacitor 10-400 pF between pin and GND


#include "PCF8575.h"

PCF8575 PCF(0x38);


////////////////////////////////////
//
// INTERRUPT ROUTINE + FLAG
Expand Down Expand Up @@ -47,6 +48,7 @@ void setup()
attachInterrupt(digitalPinToInterrupt(IRQPIN), pcf_irq, FALLING);
}


void loop()
{
uint32_t now = millis();
Expand All @@ -64,4 +66,6 @@ void loop()
delay(10);
}


// -- END OF FILE --

9 changes: 6 additions & 3 deletions examples/PCF8575_isConnected/PCF8575_isConnected.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// FILE: PCF8575_isConnected.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-01-03
//
// PUPROSE: demo
//
// PUPROSE: demo device detection


#include "PCF8575.h"

// adjust addresses if needed
PCF8575 PCF(0x39);


void setup()
{
Serial.begin(115200);
Expand All @@ -32,8 +32,11 @@ void setup()
}
}


void loop()
{
}


// -- END OF FILE --

10 changes: 7 additions & 3 deletions examples/PCF8575_performance/PCF8575_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// FILE: PCF8575_performance.ino
// AUTHOR: Rob Tillaart
// DATE: 2021-01-24
//
// PUPROSE: test PCF8575 library


#include "PCF8575.h"

PCF8575 PCF(0x38);
Expand All @@ -13,6 +13,7 @@ uint32_t start, stop;

volatile uint16_t x;


void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -41,10 +42,13 @@ void setup()
Serial.println(stop - start);
delay(1000);
}

}


void loop()
{

}


// -- END OF FILE --

10 changes: 9 additions & 1 deletion examples/PCF8575_test/PCF8575_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
// PUPROSE: test PCF8575 library
// URL: https://github.com/RobTillaart/PCF8575


#include "PCF8575.h"

PCF8575 PCF(0x38);


void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("PCF8575_test version: ");
Serial.println(PCF8575_LIB_VERSION);

PCF.begin();

uint16_t x = PCF.read16();
Expand All @@ -24,6 +26,7 @@ void setup()
delay(1000);
}


void loop()
{
Serial.println("HLT");
Expand All @@ -36,6 +39,7 @@ void loop()
}
}


void doHigh()
{
PCF.write(4, HIGH);
Expand All @@ -44,6 +48,7 @@ void doHigh()
printHex(x);
}


void doLow()
{
PCF.write(4, LOW);
Expand All @@ -52,6 +57,7 @@ void doLow()
printHex(x);
}


void doToggle()
{
PCF.toggle(4);
Expand All @@ -69,4 +75,6 @@ void printHex(uint16_t x)
Serial.println(x, HEX);
}


// -- END OF FILE --

Loading

0 comments on commit a2131cf

Please sign in to comment.