mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
49 lines
1.0 KiB
C++
49 lines
1.0 KiB
C++
#include "Arduino.h"
|
|
#include "PCF8574.h"
|
|
|
|
// For arduino uno only pin 1 and 2 are interrupted
|
|
#define ARDUINO_UNO_INTERRUPTED_PIN 2
|
|
|
|
// Function interrupt
|
|
void keyChangedOnPCF8574();
|
|
|
|
// Set i2c address
|
|
PCF8574 pcf8574(0x39, ARDUINO_UNO_INTERRUPTED_PIN, keyChangedOnPCF8574);
|
|
unsigned long timeElapsed;
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
|
|
pcf8574.pinMode(P0, OUTPUT);
|
|
pcf8574.pinMode(P1, INPUT);
|
|
pcf8574.pinMode(P2, INPUT);
|
|
pcf8574.begin();
|
|
|
|
Serial.println("START");
|
|
|
|
timeElapsed = millis();
|
|
}
|
|
|
|
bool keyChanged = false;
|
|
void loop()
|
|
{
|
|
if (keyChanged){
|
|
PCF8574::DigitalInput di = pcf8574.digitalReadAll();
|
|
Serial.print("READ VALUE FROM PCF P1: ");
|
|
Serial.print(di.p0);
|
|
Serial.print(" - ");
|
|
Serial.print(di.p1);
|
|
Serial.print(" - ");
|
|
Serial.print(di.p2);
|
|
Serial.print(" - ");
|
|
Serial.println(di.p3);
|
|
// delay(5);
|
|
keyChanged= false;
|
|
}
|
|
}
|
|
|
|
void keyChangedOnPCF8574(){
|
|
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
|
|
keyChanged = true;
|
|
}
|