mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
Update to get the state of OUTPUT PINs, and a full encoder example
This commit is contained in:
parent
64772d744f
commit
d54594fbec
13
PCF8574.cpp
13
PCF8574.cpp
@ -491,6 +491,15 @@ void PCF8574::readBuffer(bool force){
|
|||||||
if ((bit(6) & readMode)>0) digitalInput.p6 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
|
if ((bit(6) & readMode)>0) digitalInput.p6 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
|
||||||
if ((bit(7) & readMode)>0) digitalInput.p7 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
|
if ((bit(7) & readMode)>0) digitalInput.p7 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
|
||||||
|
|
||||||
|
if ((bit(0) & writeMode)>0) digitalInput.p0 = ((writeByteBuffered & bit(0))>0)?HIGH:LOW;
|
||||||
|
if ((bit(1) & writeMode)>0) digitalInput.p1 = ((writeByteBuffered & bit(1))>0)?HIGH:LOW;
|
||||||
|
if ((bit(2) & writeMode)>0) digitalInput.p2 = ((writeByteBuffered & bit(2))>0)?HIGH:LOW;
|
||||||
|
if ((bit(3) & writeMode)>0) digitalInput.p3 = ((writeByteBuffered & bit(3))>0)?HIGH:LOW;
|
||||||
|
if ((bit(4) & writeMode)>0) digitalInput.p4 = ((writeByteBuffered & bit(4))>0)?HIGH:LOW;
|
||||||
|
if ((bit(5) & writeMode)>0) digitalInput.p5 = ((writeByteBuffered & bit(5))>0)?HIGH:LOW;
|
||||||
|
if ((bit(6) & writeMode)>0) digitalInput.p6 = ((writeByteBuffered & bit(6))>0)?HIGH:LOW;
|
||||||
|
if ((bit(7) & writeMode)>0) digitalInput.p7 = ((writeByteBuffered & bit(7))>0)?HIGH:LOW;
|
||||||
|
|
||||||
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
||||||
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
DEBUG_PRINT("Buffer hight value readed set readed ");
|
DEBUG_PRINT("Buffer hight value readed set readed ");
|
||||||
@ -524,7 +533,7 @@ void PCF8574::readBuffer(bool force){
|
|||||||
DEBUG_PRINT("Buffer value ");
|
DEBUG_PRINT("Buffer value ");
|
||||||
DEBUG_PRINTLN(byteBuffered, BIN);
|
DEBUG_PRINTLN(byteBuffered, BIN);
|
||||||
|
|
||||||
byte byteRead = byteBuffered;
|
byte byteRead = byteBuffered | writeByteBuffered;
|
||||||
|
|
||||||
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
||||||
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
@ -597,6 +606,8 @@ uint8_t PCF8574::digitalRead(uint8_t pin, bool forceReadNow){
|
|||||||
byteBuffered = bit(pin) ^ byteBuffered;
|
byteBuffered = bit(pin) ^ byteBuffered;
|
||||||
DEBUG_PRINT(" ...Buffer low value readed set readed ");
|
DEBUG_PRINT(" ...Buffer low value readed set readed ");
|
||||||
DEBUG_PRINT(byteBuffered, BIN);
|
DEBUG_PRINT(byteBuffered, BIN);
|
||||||
|
}else if(bit(pin) & writeByteBuffered){
|
||||||
|
value = HIGH;
|
||||||
}
|
}
|
||||||
DEBUG_PRINT(" ...Return value ");
|
DEBUG_PRINT(" ...Return value ");
|
||||||
DEBUG_PRINTLN(value);
|
DEBUG_PRINTLN(value);
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* PCF8574 GPIO Port Expand
|
||||||
|
* https://www.mischianti.org
|
||||||
|
*
|
||||||
|
* PCF8574 ----- WeMos
|
||||||
|
* A0 ----- GRD
|
||||||
|
* A1 ----- GRD
|
||||||
|
* A2 ----- GRD
|
||||||
|
* VSS ----- GRD
|
||||||
|
* VDD ----- 5V/3.3V
|
||||||
|
* SDA ----- D1(PullUp)
|
||||||
|
* SCL ----- D2(PullUp)
|
||||||
|
* INT ----- INT(PullUp)
|
||||||
|
*
|
||||||
|
* P0 ----------------- ENCODER PIN A
|
||||||
|
* P1 ----------------- ENCODER PIN B
|
||||||
|
* P2 ----------------- ENCODER BUTTON
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "PCF8574.h"
|
||||||
|
|
||||||
|
int encoderPinA = P0;
|
||||||
|
int encoderPinB = P1;
|
||||||
|
|
||||||
|
#define INTERRUPTED_PIN D7
|
||||||
|
|
||||||
|
void ICACHE_RAM_ATTR updateEncoder();
|
||||||
|
|
||||||
|
// initialize library
|
||||||
|
PCF8574 pcf8574(0x38, INTERRUPTED_PIN, updateEncoder);
|
||||||
|
|
||||||
|
volatile long encoderValue = 0;
|
||||||
|
uint8_t encoderButtonVal = HIGH;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin (9600);
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
// encoder pins
|
||||||
|
pcf8574.encoder(encoderPinA, encoderPinB);
|
||||||
|
// encoder button
|
||||||
|
pcf8574.pinMode(P2, INPUT);
|
||||||
|
|
||||||
|
// Start library
|
||||||
|
pcf8574.begin();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
// The loop function is called in an endless loop
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (changed){
|
||||||
|
Serial.print("ENCODER --> ");
|
||||||
|
Serial.print(encoderValue);
|
||||||
|
Serial.print(" - BUTTON --> ");
|
||||||
|
Serial.println(encoderButtonVal?"HIGH":"LOW");
|
||||||
|
changed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valPrecEncoderButton = LOW;
|
||||||
|
void updateEncoder(){
|
||||||
|
changed = pcf8574.readEncoderValue(encoderPinA, encoderPinB, &encoderValue);
|
||||||
|
|
||||||
|
// int vale = pcf8574.readEncoderValue(encoderPinA, encoderPinB);
|
||||||
|
// if (vale!=0){
|
||||||
|
// changed = true;
|
||||||
|
// }
|
||||||
|
// encoderValue = encoderValue + vale;
|
||||||
|
|
||||||
|
// Button management
|
||||||
|
encoderButtonVal = pcf8574.digitalRead(P2);
|
||||||
|
if (encoderButtonVal!=valPrecEncoderButton){
|
||||||
|
changed = true; // Chnged the value of button
|
||||||
|
valPrecEncoderButton = encoderButtonVal;
|
||||||
|
}
|
||||||
|
}
|
66
resources/Article/mushroom.svg
Normal file
66
resources/Article/mushroom.svg
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="88.949463mm"
|
||||||
|
height="72.565392mm"
|
||||||
|
viewBox="0 0 88.949463 72.565391"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="mushroom.svg">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.8"
|
||||||
|
inkscape:cx="139.19796"
|
||||||
|
inkscape:cy="128.17467"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="2400"
|
||||||
|
inkscape:window-height="1421"
|
||||||
|
inkscape:window-x="2391"
|
||||||
|
inkscape:window-y="-9"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Livello 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-49.761564,-80.686663)">
|
||||||
|
<path
|
||||||
|
style="fill:#000000;stroke-width:0.36276054"
|
||||||
|
d="m 87.505839,152.96667 c -9.147717,-1.24127 -13.011682,-5.38599 -13.499729,-14.48061 -0.229918,-4.28448 -0.124827,-4.73624 2.878813,-12.37461 2.36918,-6.02492 2.199808,-10.97386 -0.422963,-12.35872 -2.202175,-1.16278 -5.799189,-0.10917 -5.863597,1.71741 -0.05525,1.56713 -1.019661,3.13738 -2.385527,3.88413 -1.120009,0.61234 -1.884061,0.73271 -4.650758,0.73271 -2.883853,0 -3.629334,-0.12836 -5.78355,-0.99584 -2.950457,-1.18811 -4.206563,-2.31092 -5.989956,-5.35429 -4.061333,-6.93066 -1.974396,-14.443756 5.853358,-21.072388 6.803471,-5.761256 16.050558,-9.677299 26.826192,-11.360605 5.024393,-0.784882 13.215758,-0.826537 18.519088,-0.09418 18.29028,2.525796 33.3682,12.699104 35.52816,23.971423 1.06716,5.56915 -2.32875,11.58299 -7.80297,13.81843 -1.68647,0.68868 -2.45263,0.80791 -4.48862,0.6986 -3.95485,-0.21234 -8.28017,-2.26996 -8.30557,-3.95103 -0.005,-0.32722 -0.54054,-1.0233 -1.19022,-1.54683 -1.61403,-1.30069 -3.57646,-1.30045 -5.37908,6.4e-4 -1.30763,0.94382 -1.31939,0.97884 -1.2858,3.82636 0.0281,2.38283 0.35913,3.8061 1.93747,8.33043 2.78492,7.98305 3.15242,11.91074 1.63049,17.42707 -1.3944,5.05405 -5.11898,7.9024 -11.83303,9.04922 -2.876431,0.49132 -11.087416,0.56755 -14.292201,0.13268 z"
|
||||||
|
id="path826"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in New Issue
Block a user