#include <PCF8574.h>
PCF8574 pcf20(0x20);
#include "KeyboardPolling.h"
void setup() {
Serial.begin(9600); // Инициализация последовательной связи
setupKeyboardPolling(); // Инициализация опроса клавиатуры
attachInterrupt(digitalPinToInterrupt(2), keyboardInterrupt, CHANGE);
Serial.print("PCF8574_LIB_VERSION:\t");
Serial.println(PCF8574_LIB_VERSION);
if (!pcf20.begin()) {
Serial.println("Chip not responding.");
}
if (!pcf20.isConnected()) {
Serial.println("could not initialize... => not connected");
while (1);
uint8_t value = pcf20.read8();
Serial.print("0x20 read: ");
Serial.println(value, HEX);
}
}
void loop() {
if (isKeyPressed()) { // Проверяем, была ли нажата клавиша
byte keys = readKeys(); // Чтение нажатых клавиш
printKeys(keys); // Вывод нажатых клавиш в монитор последовательного порта
clearKeyPressFlag(); // Сброс флага нажатия клавиши
}
}
void printKeys(byte keys) {
for (int i = 0; i < 8; i++) {
if (keys & (1 << i)) {
Serial.print("Key ");
Serial.println(i + 1);
}
}
}