From cfa7192f5f6abe6c559da5cdfd371fec459c5d52 Mon Sep 17 00:00:00 2001 From: Anatole SCHRAMM Date: Thu, 2 May 2019 17:20:52 +0200 Subject: [PATCH] Added the togglePin method to the library --- src/libs/PCF8574/PCF8574.cpp | 13 +++++++++++++ src/libs/PCF8574/PCF8574.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/libs/PCF8574/PCF8574.cpp b/src/libs/PCF8574/PCF8574.cpp index d211033..25bf2c2 100644 --- a/src/libs/PCF8574/PCF8574.cpp +++ b/src/libs/PCF8574/PCF8574.cpp @@ -51,6 +51,19 @@ void PCF8574::digitalWrite(Pin pin, boolean mode) _twc.endTransmission(); } +void PCF8574::togglePin(Pin pin) +{ + //We first check that the pin is an output + if((_pddr & pin) == 0) + return; + + _pinConfig = (_pinConfig & pin) == 0 ? _pinConfig | pin : _pinConfig & ~pin; + + _twc.beginTransmission(_address); + _twc.write(_pinConfig); + _twc.endTransmission(); +} + boolean PCF8574::digitalRead(Pin pin) { uint8_t reg = 0b00000000; diff --git a/src/libs/PCF8574/PCF8574.h b/src/libs/PCF8574/PCF8574.h index ae0ce41..eecd626 100644 --- a/src/libs/PCF8574/PCF8574.h +++ b/src/libs/PCF8574/PCF8574.h @@ -22,6 +22,7 @@ class PCF8574 void digitalReadAll(boolean array[]); boolean getPinMode(Pin pin); void getPinModeAll(boolean array[]); + void togglePin(Pin pin); private: TwoWire &_twc; uint8_t _address;