#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <avr/wdt.h>
// LCD I2C
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Entrées IR (D22 à D36)
const int irPins[15] = {
22, 23, 24, 25, 26,
27, 28, 29, 30, 31,
32, 33, 34, 35, 36
};
// Sorties Sunlite (D2 à D9)
const int outPins[8] = {
2, 3, 4, 5, 6, 7, 8, 9
};
// Bouton SAV
const int savButton = 37;
// Table de correspondance 16 → 8
const int map16to8[16] = {
0, 1, 2, 3, 4, 5, 6, 7,
0, 1, 2, 3, 4, 5, 6, 7
};
void setup() {
// Entrées IR
for (int i = 0; i < 15; i++) {
pinMode(irPins[i], INPUT);
}
// Sorties Sunlite
for (int i = 0; i < 8; i++) {
pinMode(outPins[i], OUTPUT);
digitalWrite(outPins[i], HIGH); // repos = inactif
}
pinMode(savButton, INPUT_PULLUP);
// LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Interface IR/DMX");
// Watchdog
wdt_enable(WDTO_1S);
}
void loop() {
int activeIR = detectActiveInput();
int mappedOutput = applyMapping(activeIR);
updateOutputs(mappedOutput);
displayStatus(activeIR, mappedOutput);
wdt_reset();
}
int detectActiveInput() {
for (int i = 0; i < 15; i++) {
if (digitalRead(irPins[i]) == HIGH) {
return i + 1;
}
}
return 0;
}
int applyMapping(int irValue) {
if (irValue == 0) return -1;
return map16to8[irValue];
}
void updateOutputs(int outIndex) {
for (int i = 0; i < 8; i++) {
digitalWrite(outPins[i], HIGH);
}
if (outIndex >= 0 && outIndex < 8) {
digitalWrite(outPins[outIndex], LOW);
}
}
void displayStatus(int ir, int out) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("IR: ");
lcd.print(ir);
lcd.setCursor(0, 1);
lcd.print("OUT: ");
lcd.print(out + 1);
}RESET
SAV
Simulation sorties décodeur IR