Bonjour, je viens vous demandez de l'aide car je n'en peut plus de cette puce PCF8574. Peut importe le code je teste rien ne s'affiche dans la console quand appui sur le clavier.
Voila pour le câblage:
Je sais que le clavier fonctionne que je les testé en direct sans passé par la puce PCF8574 avec ce code:
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}
void loop(){
char key = keypad.getKey();
if (key){
Serial.println(key);
}
}
Le code avec le module PCF8574:
#include <Wire.h>
#define PCF8574_ADDR 0x20
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
char key = getKey();
if (key != 0) {
Serial.println("Touche appuyée : " + String(key));
delay(500); // Attendez un court instant pour éviter les rebonds
}
}
char getKey() {
Wire.requestFrom(PCF8574_ADDR, 1);
if (Wire.available()) {
byte val = Wire.read();
for (int i = 0; i < 16; i++) {
if ((val & (1 << i)) == 0) {
return getChar(i);
}
}
}
return 0;
}
char getChar(int index) {
// Vous pouvez personnaliser cette fonction pour attribuer des caractères aux différentes touches
char keys[16] = {
'1', '2', '3', 'A',
'4', '5', '6', 'B',
'7', '8', '9', 'C',
'*', '0', '#', 'D'
};
return keys[index];
}
J'ai voulu voir ce qui sortait du module PCF8574 avec ce code:
#include <Wire.h>
#define PCF8574_ADDR 0x20
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
byte portState = readPCF8574();
Serial.print("État du port PCF8574: ");
Serial.println(portState, BIN);
delay(1000); // Ajoutez un délai si nécessaire pour éviter une lecture trop fréquente
}
byte readPCF8574() {
Wire.requestFrom(PCF8574_ADDR, 1);
if (Wire.available()) {
return Wire.read();
}
return 0;
}
La réponse: 11111111 que l'appui ou pas
Je comprend pas pourquoi sa donne rien
Merci par avance