This is my code:
#include <PCF8574.h>
#include <Wire.h>
PCF8574 pcf20(0x20); // I2C Expander
class ButtonSend {
int buttonPin;
int buttonState;
int lastButtonState;
int reading;
unsigned long lastDebounceTime;
unsigned long debounceDelay;
public:
ButtonSend(int pin) {
buttonPin = pin;
lastButtonState = LOW;
lastDebounceTime = 0;
debounceDelay = 50;
pcf20.read(buttonPin);
pcf20.write(buttonPin, HIGH);
}
void Update() {
reading = pcf20.read(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
Serial.println("click");
}
}
}
lastButtonState = reading;
}
};
void setup() {
pcf20.begin(); // I2C Expander
}
ButtonSend btn1(2);
void loop() {
btn1.Update();
}
I'm trying to use I2C expander library - PCF8574 inside my class. I use this library Arduino/libraries/PCF8574 at master · RobTillaart/Arduino · GitHub It compiles ok, but after uploading to Arduino it is not responding - not availaible by port COM. To resotre Arduino I need to upload another project just after restart. I think this can be problem with inheritance, but my knowledge about C++ is poor.