mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
parent
0dc02aa919
commit
3d8298da47
@ -4,9 +4,12 @@ Tutorial:
|
|||||||
|
|
||||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8574. Check that the PCF8574 folder contains `PCF8574\\.cpp` and `PCF8574.h`. Place the DHT library folder your `<arduinosketchfolder>/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder PCF8574. Check that the PCF8574 folder contains `PCF8574\\.cpp` and `PCF8574.h`. Place the DHT library folder your `<arduinosketchfolder>/libraries/` folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
||||||
|
|
||||||
# Reef complete PCF8574 digital input and output expander with i2c bus.
|
# Reef complete PCF8574 PCF8574AP digital input and output expander with i2c bus.
|
||||||
I try to simplify the use of this IC, with a minimal set of operation.
|
I try to simplify the use of this IC, with a minimal set of operation.
|
||||||
|
|
||||||
|
PCF8574P address map 0x20-0x27
|
||||||
|
PCF8574AP address map 0x38-0x3f
|
||||||
|
|
||||||
Constructor:
|
Constructor:
|
||||||
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
|
you must pas the address of i2c (to check the adress use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner))
|
||||||
```cpp
|
```cpp
|
||||||
|
68
examples/interruptWemos/interruptWemos.ino
Normal file
68
examples/interruptWemos/interruptWemos.ino
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* PCF8574 GPIO Port Expand
|
||||||
|
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
|
||||||
|
*
|
||||||
|
* PCF8574 ----- WeMos
|
||||||
|
* A0 ----- GRD
|
||||||
|
* A1 ----- GRD
|
||||||
|
* A2 ----- GRD
|
||||||
|
* VSS ----- GRD
|
||||||
|
* VDD ----- 5V/3.3V
|
||||||
|
* SDA ----- GPIO_4
|
||||||
|
* SCL ----- GPIO_5
|
||||||
|
* INT ----- GPIO_13
|
||||||
|
*
|
||||||
|
* P0 ----------------- BUTTON0
|
||||||
|
* P1 ----------------- BUTTON1
|
||||||
|
* P2 ----------------- BUTTON2
|
||||||
|
* P3 ----------------- BUTTON3
|
||||||
|
* P4 ----------------- BUTTON4
|
||||||
|
* P5 ----------------- BUTTON5
|
||||||
|
* P6 ----------------- BUTTON6
|
||||||
|
* P7 ----------------- BUTTON7
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "PCF8574.h" // https://github.com/xreef/PCF8574_library
|
||||||
|
|
||||||
|
#define ESP8266_INTERRUPTED_PIN 13
|
||||||
|
|
||||||
|
// Set i2c address
|
||||||
|
PCF8574 pcf8574(0x20);
|
||||||
|
|
||||||
|
// Function interrupt
|
||||||
|
bool keyPressed = false;
|
||||||
|
|
||||||
|
void keyPressedOnPCF8574(){
|
||||||
|
// Serial.println("keyPressedOnPCF8574");
|
||||||
|
keyPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
if (keyPressed){
|
||||||
|
PCF8574::DigitalInput val = pcf8574.digitalReadAll();
|
||||||
|
if (val.p0==HIGH) Serial.println("KEY0 PRESSED");
|
||||||
|
if (val.p1==HIGH) Serial.println("KEY1 PRESSED");
|
||||||
|
if (val.p2==HIGH) Serial.println("KEY2 PRESSED");
|
||||||
|
if (val.p3==HIGH) Serial.println("KEY3 PRESSED");
|
||||||
|
if (val.p4==HIGH) Serial.println("KEY4 PRESSED");
|
||||||
|
if (val.p5==HIGH) Serial.println("KEY5 PRESSED");
|
||||||
|
if (val.p6==HIGH) Serial.println("KEY6 PRESSED");
|
||||||
|
if (val.p7==HIGH) Serial.println("KEY7 PRESSED");
|
||||||
|
keyPressed= false;
|
||||||
|
}
|
||||||
|
}
|
51
examples/ledWemos/ledWemos.ino
Normal file
51
examples/ledWemos/ledWemos.ino
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* PCF8574 GPIO Port Expand
|
||||||
|
* http://nopnop2002.webcrow.jp/WeMos/WeMos-25.html
|
||||||
|
*
|
||||||
|
* PCF8574 ----- WeMos
|
||||||
|
* A0 ----- GRD
|
||||||
|
* A1 ----- GRD
|
||||||
|
* A2 ----- GRD
|
||||||
|
* VSS ----- GRD
|
||||||
|
* VDD ----- 5V/3.3V
|
||||||
|
* SDA ----- GPIO_4(PullUp)
|
||||||
|
* SCL ----- GPIO_5(PullUp)
|
||||||
|
*
|
||||||
|
* P0 ----------------- LED0
|
||||||
|
* P1 ----------------- LED1
|
||||||
|
* P2 ----------------- LED2
|
||||||
|
* P3 ----------------- LED3
|
||||||
|
* P4 ----------------- LED4
|
||||||
|
* P5 ----------------- LED5
|
||||||
|
* P6 ----------------- LED6
|
||||||
|
* P7 ----------------- LED7
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "PCF8574.h" // https://github.com/xreef/PCF8574_library
|
||||||
|
|
||||||
|
// Set i2c address
|
||||||
|
PCF8574 pcf8574(0x20);
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
// Set pinMode to OUTPUT
|
||||||
|
for(int i=0;i<8;i++) {
|
||||||
|
pcf8574.pinMode(i, OUTPUT);
|
||||||
|
}
|
||||||
|
pcf8574.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
static int pin = 0;
|
||||||
|
pcf8574.digitalWrite(pin, HIGH);
|
||||||
|
delay(1000);
|
||||||
|
pcf8574.digitalWrite(pin, LOW);
|
||||||
|
delay(1000);
|
||||||
|
pin++;
|
||||||
|
if (pin > 7) pin = 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user