mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
Merge branch 'Test_Digital_Write_All'
This commit is contained in:
commit
3f7fb745b6
61
PCF8574.cpp
61
PCF8574.cpp
@ -679,4 +679,65 @@ bool PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
||||
return this->isLastTransmissionSuccess();
|
||||
};
|
||||
|
||||
#ifndef PCF8574_LOW_MEMORY
|
||||
/**
|
||||
* Read value of all INPUT pin
|
||||
* Debounce read more fast than 10millis, non managed for interrupt mode
|
||||
* @return
|
||||
*/
|
||||
void PCF8574::setVal(uint8_t pin, uint8_t value){
|
||||
if (value==HIGH){
|
||||
writeByteBuffered = writeByteBuffered | bit(pin);
|
||||
byteBuffered = writeByteBuffered | bit(pin);
|
||||
}else{
|
||||
writeByteBuffered = writeByteBuffered & ~bit(pin);
|
||||
byteBuffered = writeByteBuffered & ~bit(pin);
|
||||
}
|
||||
|
||||
}
|
||||
bool PCF8574::digitalWriteAll(PCF8574::DigitalInput digitalInput){
|
||||
|
||||
setVal(P0, digitalInput.p0);
|
||||
setVal(P1, digitalInput.p1);
|
||||
setVal(P2, digitalInput.p2);
|
||||
setVal(P3, digitalInput.p3);
|
||||
setVal(P4, digitalInput.p4);
|
||||
setVal(P5, digitalInput.p5);
|
||||
setVal(P6, digitalInput.p6);
|
||||
setVal(P7, digitalInput.p7);
|
||||
|
||||
return digitalWriteAllBytes(writeByteBuffered);
|
||||
}
|
||||
#else
|
||||
bool PCF8574::digitalWriteAll(byte digitalInput){
|
||||
return digitalWriteAllBytes(digitalInput);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool PCF8574::digitalWriteAllBytes(byte allpins){
|
||||
_wire->beginTransmission(_address); //Begin the transmission to PCF8574
|
||||
|
||||
// writeByteBuffered = writeByteBuffered & (~writeMode & byteBuffered);
|
||||
writeByteBuffered = allpins;
|
||||
byteBuffered = (writeByteBuffered & writeMode) | (resetInitial & readMode);
|
||||
|
||||
// byteBuffered = (writeByteBuffered & writeMode) | (byteBuffered & readMode);
|
||||
DEBUG_PRINT(" byteBuffered ");
|
||||
DEBUG_PRINTLN(byteBuffered, BIN);
|
||||
|
||||
DEBUG_PRINT("Going to write data ");
|
||||
DEBUG_PRINTLN(writeByteBuffered, BIN);
|
||||
|
||||
_wire->write(byteBuffered);
|
||||
|
||||
byteBuffered = (writeByteBuffered & writeMode) | (initialBuffer & readMode);
|
||||
|
||||
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
||||
|
||||
this->transmissionStatus = _wire->endTransmission();
|
||||
|
||||
return this->isLastTransmissionSuccess();
|
||||
|
||||
}
|
||||
|
@ -144,8 +144,11 @@ public:
|
||||
|
||||
|
||||
DigitalInput digitalReadAll(void);
|
||||
|
||||
bool digitalWriteAll(PCF8574::DigitalInput digitalInput);
|
||||
#else
|
||||
byte digitalReadAll(void);
|
||||
bool digitalWriteAll(byte digitalInput);
|
||||
#endif
|
||||
bool digitalWrite(uint8_t pin, uint8_t value);
|
||||
|
||||
@ -229,6 +232,9 @@ private:
|
||||
byte validCCW = B11100001;
|
||||
|
||||
uint8_t transmissionStatus = 0;
|
||||
|
||||
void setVal(uint8_t pin, uint8_t value);
|
||||
bool digitalWriteAllBytes(byte allpins);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -31,7 +31,12 @@ void setup()
|
||||
pcf8574.pinMode(P5, OUTPUT);
|
||||
pcf8574.pinMode(P4, OUTPUT, LOW);
|
||||
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
timeElapsed = millis();
|
||||
}
|
||||
|
@ -14,11 +14,18 @@ PCF8574 pcf8574(0x39);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
// Set pinMode to OUTPUT
|
||||
pcf8574.pinMode(P0, OUTPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
pcf8574.begin();
|
||||
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -49,7 +49,12 @@ void setup()
|
||||
pcf8574.setLatency(0);
|
||||
|
||||
// Start library
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
@ -44,7 +44,12 @@ void setup()
|
||||
pcf8574.pinMode(P2, INPUT);
|
||||
|
||||
// Start library
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,13 +42,20 @@ void keyPressedOnPCF8574(){
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
delay(1000);
|
||||
|
||||
pinMode(ESP8266_INTERRUPTED_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(ESP8266_INTERRUPTED_PIN), keyPressedOnPCF8574, FALLING);
|
||||
|
||||
for(int i=0;i<8;i++) {
|
||||
pcf8574.pinMode(i, INPUT);
|
||||
}
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -14,11 +14,17 @@ unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
pcf8574.pinMode(P0, OUTPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -14,11 +14,17 @@ unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
pcf8574.pinMode(P0, OUTPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
pcf8574.begin();
|
||||
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
timeElapsed = millis();
|
||||
}
|
||||
|
@ -20,10 +20,16 @@ unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
pcf8574.pinMode(P0, OUTPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
|
||||
timeElapsed = millis();
|
||||
|
@ -46,12 +46,19 @@ void setup()
|
||||
Serial.begin(112560);
|
||||
|
||||
I2Cone.begin(16,17,400000); // SDA pin 16, SCL pin 17, 400kHz frequency
|
||||
delay(1000);
|
||||
|
||||
// Set pinMode to OUTPUT
|
||||
for(int i=0;i<8;i++) {
|
||||
pcf8574.pinMode(i, OUTPUT);
|
||||
}
|
||||
pcf8574.begin();
|
||||
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -31,12 +31,18 @@ PCF8574 pcf8574(0x20);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
delay(1000);
|
||||
|
||||
// Set pinMode to OUTPUT
|
||||
for(int i=0;i<8;i++) {
|
||||
pcf8574.pinMode(i, OUTPUT);
|
||||
}
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
@ -20,11 +20,18 @@ unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
pcf8574.pinMode(P0, OUTPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
pcf8574.pinMode(P2, INPUT);
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
|
||||
Serial.println("START");
|
||||
|
||||
|
@ -24,11 +24,17 @@ unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
pcf8574.pinMode(P0, INPUT);
|
||||
pcf8574.pinMode(P1, INPUT);
|
||||
pcf8574.pinMode(P2, INPUT);
|
||||
pcf8574.begin();
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
Serial.println("START");
|
||||
|
||||
|
101
examples/writeAllEsp8266/writeAllEsp8266.ino
Normal file
101
examples/writeAllEsp8266/writeAllEsp8266.ino
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
KeyPressed with interrupt and digital write all
|
||||
from P4 to P7
|
||||
by Mischianti Renzo <http://www.mischianti.org>
|
||||
|
||||
https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "PCF8574.h"
|
||||
|
||||
// For arduino uno only pin 1 and 2 are interrupted
|
||||
#define ARDUINO_UNO_INTERRUPTED_PIN D3
|
||||
|
||||
// Function interrupt
|
||||
void ICACHE_RAM_ATTR keyPressedOnPCF8574();
|
||||
|
||||
// Set i2c address
|
||||
PCF8574 pcf8574(0x38, ARDUINO_UNO_INTERRUPTED_PIN, keyPressedOnPCF8574);
|
||||
unsigned long timeElapsed;
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
Serial.println("INIT");
|
||||
|
||||
pcf8574.pinMode(P0, INPUT);
|
||||
pcf8574.pinMode(P1, INPUT_PULLUP);
|
||||
pcf8574.pinMode(P2, INPUT);
|
||||
pcf8574.pinMode(P3, INPUT);
|
||||
|
||||
pcf8574.pinMode(P7, OUTPUT);
|
||||
pcf8574.pinMode(P6, OUTPUT, HIGH);
|
||||
pcf8574.pinMode(P5, OUTPUT, LOW);
|
||||
pcf8574.pinMode(P4, OUTPUT, LOW);
|
||||
|
||||
Serial.print("Init pcf8574...");
|
||||
if (pcf8574.begin()){
|
||||
Serial.println("OK");
|
||||
}else{
|
||||
Serial.println("KO");
|
||||
}
|
||||
|
||||
Serial.println("START");
|
||||
timeElapsed = millis();
|
||||
}
|
||||
unsigned long lastSendTime = 0; // last send time
|
||||
unsigned long interval = 3000; // interval between sends
|
||||
|
||||
bool startVal = HIGH;
|
||||
|
||||
bool keyPressed = false;
|
||||
void loop()
|
||||
{
|
||||
if (keyPressed){
|
||||
uint8_t val0 = pcf8574.digitalRead(P0);
|
||||
uint8_t val1 = pcf8574.digitalRead(P1);
|
||||
uint8_t val2 = pcf8574.digitalRead(P2);
|
||||
uint8_t val3 = pcf8574.digitalRead(P3);
|
||||
Serial.print("P0 ");
|
||||
Serial.print(val0);
|
||||
Serial.print(" P1 ");
|
||||
Serial.println(val1);
|
||||
Serial.print("P2 ");
|
||||
Serial.print(val2);
|
||||
Serial.print(" P3 ");
|
||||
Serial.println(val3);
|
||||
keyPressed= false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (millis() - lastSendTime > interval) {
|
||||
Serial.print("WRITE VALUE FROM P4 TO P7 ");
|
||||
Serial.println(startVal);
|
||||
|
||||
// pcf8574.digitalWrite(P7, startVal);
|
||||
bool startVal2 = LOW;
|
||||
if (startVal==HIGH) {
|
||||
startVal = LOW;
|
||||
startVal2 = HIGH;
|
||||
}else{
|
||||
startVal = HIGH;
|
||||
startVal2 = LOW;
|
||||
}
|
||||
PCF8574::DigitalInput digitalInput;
|
||||
digitalInput.p4 = startVal2;
|
||||
digitalInput.p5 = startVal;
|
||||
digitalInput.p6 = startVal2;
|
||||
digitalInput.p7 = startVal;
|
||||
|
||||
pcf8574.digitalWriteAll(digitalInput);
|
||||
lastSendTime = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void keyPressedOnPCF8574(){
|
||||
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
|
||||
keyPressed = true;
|
||||
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/xreef/PCF8574_library.git"
|
||||
},
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
name=PCF8574 library
|
||||
version=2.2.0
|
||||
version=2.2.1
|
||||
author=Renzo Mischianti <renzo.mischianti@gmail.com>
|
||||
maintainer=Renzo Mischianti <renzo.mischianti@gmail.com>
|
||||
sentence=Arduino/ESP8266 library for PCF8574
|
||||
paragraph=Use i2c digital expander with Arduino and ESP8266. Can read write digital values with only 2 wire (perfect for ESP-01).
|
||||
paragraph=Use i2c digital expander with Arduino, esp32 and ESP8266. Can read write digital values with only 2 wire. Very simple and encoder support.
|
||||
category=Sensors
|
||||
url=https://github.com/xreef/PCF8574_library
|
||||
url=https://www.mischianti.org/category/my-libraries/pcf8574/
|
||||
repository=https://github.com/xreef/PCF8574_library
|
||||
architectures=*
|
||||
includes=PCF8574.h
|
Loading…
Reference in New Issue
Block a user