#include <IRremote.h>
// Broches du récepteur infrarouge
const int receiverPins[6] = {2, 3, 4, 5, 6, 7};
// Utilisé pour stocker la valeur lue pour chaque broche
int values[6] = {0, 0, 0, 0, 0, 0};
// Horodatage pour vérifier la stabilité du signal
unsigned long stableSince[6] = {0, 0, 0, 0, 0, 0};
// Temps de stabilisation requis (ms)
const unsigned long stableTime = 2000;
void setup() {
Serial.begin(9600);
for (int i = 0; i < 6; i++) {
pinMode(receiverPins[i], INPUT);
}
}
void loop() {
bool allStable = true;
unsigned long currentTime = millis();
// Lire l'état de tous les récepteurs IR et vérifier la stabilité
for (int i = 0; i < 6; i++) {
int readValue = digitalRead(receiverPins[i]);
if (readValue != values[i] || stableSince[i] == 0) {
values[i] = readValue;
stableSince[i] = currentTime; // Temps de stabilisation de la réinitialisation
allStable = false;
} else if (currentTime - stableSince[i] < stableTime) {
allStable = false;
}
}
// Lorsque tous les signaux sont stables pendant plus de 2 secondes, décoder et émettre le caractère correspondant
if (allStable) {
char decodedChar = decodeCharacter(values);
Serial.println(decodedChar);
// Remise à zéro du temps de stabilisation pour éviter les doubles sorties
for (int i = 0; i < 6; i++) {
stableSince[i] = 0;
}
}
}
// Décoder les caractères en fonction de la forme du signal
char decodeCharacter(int signalPattern[6]) {
// Caractères correspondant aux modes de signalisation, tels que définis dans la table de vérité
const char characters[] = "ABC...Z012...9"; // Modèle de correspondance complémentaire
const int patterns[][6] = {
{1, 1, 1, 1, 1, 0}, // A
{1, 1, 1, 1, 0, 1}, // B
{1, 1, 1, 0, 1, 1}, // C
{1, 1, 0, 1, 1, 1}, // D
{1, 0, 1, 1, 1, 1}, // E
{0, 1, 1, 1, 1, 1}, // F
{1, 1, 1, 1, 0, 0}, // G
{1, 1, 1, 0, 1, 0}, // H
{1, 1, 0, 1, 1, 0}, // I
{1, 0, 1, 1, 1, 0}, // J
{0, 1, 1, 1, 1, 0}, // K
{1, 1, 1, 0, 0, 1}, // L
{1, 1, 0, 1, 0, 1}, // M
{1, 0, 1, 1, 0, 1}, // N
{0, 1, 1, 1, 1, 0}, // O
{1, 1, 0, 0, 1, 1}, // P
{1, 0, 1, 0, 1, 1}, // Q
{0, 1, 1, 0, 1, 1}, // R
{1, 0, 0, 1, 1, 1}, // S
{0, 1, 0, 1, 1, 1}, // T
{0, 0, 1, 1, 1, 1}, // U
{1, 1, 1, 0, 0, 0}, // V
{1, 1, 0, 0, 0, 1}, // W
{1, 0, 0, 0, 1, 1}, // X
{0, 0, 0, 1, 1, 1}, // Y
{1, 1, 0, 0, 0, 0}, // Z
{1, 0, 0, 1, 0, 0}, // 1
{0, 0, 1, 0, 0, 1}, // 2
{0, 0, 0, 1, 0, 1}, // 3
{0, 0, 0, 0, 1, 1}, // 4
{1, 1, 0, 0, 0, 0}, // 5
{1, 0, 0, 0, 0, 1}, // 6
{1, 0, 0, 0, 0, 0}, // 7
{0, 0, 0, 0, 0, 1}, // 8
{0, 0, 0, 0, 1, 0}, // 9
};
for (int i = 0; i < sizeof(characters) - 1; i++) {
bool match = true;
for (int j = 0; j < 6; j++) {
if (patterns[i][j] != signalPattern[j]) {
match = false;
break;
}
}
if (match) {
return characters[i];
}
}
return '?';
}