#include "mbed.h"
#include "TextLCD.h"
/* ====== Déclarations ====== */
// LED (lumière)
DigitalOut led(PA_5);
// Buzzer (alarme)
DigitalOut buzzer(PA_6);
// Capteur PIR (interruption)
InterruptIn pir(PA_1);
// Capteur température (LM35)
AnalogIn tempSensor(PA_0);
// LCD 16x2
TextLCD lcd(PB_0, PB_1, PB_2, PB_3, PB_4, PB_5);
// Variables globales
volatile bool motionDetected = false;
/* ====== Fonction interruption PIR ====== */
void motion_isr() {
motionDetected = true;
}
/* ====== Programme principal ====== */
int main() {
// Initialisation
lcd.cls();
lcd.printf("Smart Home\nSystem Ready");
// Configuration interruption
pir.rise(&motion_isr);
while (true) {
// Lecture température
float voltage = tempSensor.read() * 3.3;
float temperature = voltage * 100.0; // LM35
lcd.cls();
lcd.printf("Temp: %.1f C\n", temperature);
// Gestion température
if (temperature > 30.0) {
lcd.printf("Ventilateur ON");
} else {
lcd.printf("Ventilateur OFF");
}
// Gestion sécurité
if (motionDetected) {
led = 1;
buzzer = 1;
lcd.cls();
lcd.printf("ALERTE!\nMouvement");
ThisThread::sleep_for(2s);
motionDetected = false;
} else {
led = 0;
buzzer = 0;
}
ThisThread::sleep_for(1s);
}
}