#include <LiquidCrystal_I2C.h>
#include <PCF8575.h>
#define SDA_Pin 21
#define SCL_Pin 22
#define InteruptPCF_Pin 17
LiquidCrystal_I2C lcd(0x27, 40, 4);
void keyPressedOnPCF8575();
PCF8575 pcf8575(0x22); //, InteruptPCF_Pin, keyPressedOnPCF8575);
bool SwitchPresed = false;
const byte LED_Green = P8;
const byte LED_Blue = P9;
const byte LED_White = P10;
const byte LED_Red = P11;
const byte SW_Green = P0;
const byte SW_Blue = P1;
const byte SW_White = P2;
const byte SW_Red = P3;
const byte LED_ON = LOW;
const byte LED_OFF = HIGH;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(InteruptPCF_Pin, INPUT);
attachInterrupt(InteruptPCF_Pin, keyPressedOnPCF8575, RISING); // zbocze narastające
for (int ii = 0; ii <= 17; ii++) {
pcf8575.pinMode(ii, OUTPUT);
pcf8575.digitalWrite(ii, !LOW);
}
pcf8575.pinMode(LED_Green, OUTPUT);
pcf8575.pinMode(LED_Blue, OUTPUT);
pcf8575.pinMode(LED_White, OUTPUT);
pcf8575.pinMode(LED_Red, OUTPUT);
pcf8575.pinMode(SW_Green, INPUT);
pcf8575.pinMode(SW_Blue, INPUT);
pcf8575.pinMode(SW_White, INPUT);
pcf8575.pinMode(SW_Red, INPUT);
pcf8575.begin();
for (int iLED = 8; iLED <= 11; iLED++) {
pcf8575.digitalWrite(iLED, LED_ON);
// Serial.println("BLINKINg LED ");
// Serial.println(iLED);
delay(500);
pcf8575.digitalWrite(iLED, LED_OFF);
}
Wire.begin(SDA_Pin, SCL_Pin); //21, 22
lcd.init();
//lcd.init(SDA_Pin,SCL_Pin); // initialize the LCD to use user defined I2C pins
lcd.noBacklight();
lcd.backlight();
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("o ENT"); // print message at (0, 0)
lcd.setCursor(6, 0); // move cursor to (2, 1)
lcd.print("o <"); // print message at (2, 1)
lcd.setCursor(10, 0); // move cursor to (2, 1)
lcd.print("o >");
lcd.setCursor(15, 0); // move cursor to (2, 1)
lcd.print("ESC o");
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
int GreenSW = pcf8575.digitalRead(SW_Green); // read P4 RUN
int BlueSW = pcf8575.digitalRead(SW_Blue); // read P5 STOP
int WhiteSW = pcf8575.digitalRead(SW_White); // read P6
if (SwitchPresed) {
PCF8575::DigitalInput di = pcf8575.digitalReadAll();
Serial.print("READ VALUE FROM PCF: ");
Serial.print(di.p0);
Serial.print(" - ");
Serial.print(di.p1);
Serial.print(" - ");
Serial.print(di.p2);
Serial.print(" - ");
Serial.println(di.p3);
SwitchPresed = false;
}
// delay(500); // display the above for two seconds
// lcd.clear(); // clear display
// lcd.setCursor(2, 0); // move cursor to (3, 0)
// lcd.print("LCD I2C MODE"); // print message at (3, 0)
// lcd.setCursor(6, 1); // move cursor to (0, 1)
// lcd.print("16x2"); // print message at (0, 1)
// delay(500);
}
void keyPressedOnPCF8575(){
// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
SwitchPresed = true;
}nINT