From 57de082e7e4568c94b5d27b9ec3a2af85bf586d7 Mon Sep 17 00:00:00 2001 From: "PC-PAUL\\paulf" Date: Fri, 7 Mar 2025 12:17:17 +0100 Subject: [PATCH] Detection OK, changement couleur LED et alarme sonore OK --- .gitignore | 102 +++++++++++++++++++++++++++++++--------------- AlarmeESP32.ino | 30 ++++++++++++++ FirebaseHandler.h | 0 branchements.h | 14 +++++++ ctrlLed.h | 64 +++++++++++++++++++++++++++++ ctrlRfid.h | 0 ctrlSpeaker.h | 34 ++++++++++++++++ 7 files changed, 211 insertions(+), 33 deletions(-) create mode 100644 AlarmeESP32.ino create mode 100644 FirebaseHandler.h create mode 100644 branchements.h create mode 100644 ctrlLed.h create mode 100644 ctrlRfid.h create mode 100644 ctrlSpeaker.h diff --git a/.gitignore b/.gitignore index e257658..47ded03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,70 @@ -# ---> C++ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app +app/bin/ +app/pde.jar +build/macosx/work/ +arduino-core/bin/ +arduino-core/arduino-core.jar +hardware/arduino/bootloaders/caterina_LUFA/Descriptors.o +hardware/arduino/bootloaders/caterina_LUFA/Descriptors.lst +hardware/arduino/bootloaders/caterina_LUFA/Caterina.sym +hardware/arduino/bootloaders/caterina_LUFA/Caterina.o +hardware/arduino/bootloaders/caterina_LUFA/Caterina.map +hardware/arduino/bootloaders/caterina_LUFA/Caterina.lst +hardware/arduino/bootloaders/caterina_LUFA/Caterina.lss +hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf +hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep +hardware/arduino/bootloaders/caterina_LUFA/.dep/ +build/*.zip +build/*.tar.bz2 +build/windows/work/ +build/windows/*.zip +build/windows/*.tgz +build/windows/*.tar.bz2 +build/windows/libastylej* +build/windows/liblistSerials* +build/windows/arduino-*.zip +build/windows/dist/*.tar.gz +build/windows/dist/*.tar.bz2 +build/windows/launch4j-*.tgz +build/windows/launch4j-*.zip +build/windows/launcher/launch4j +build/windows/WinAVR-*.zip +build/macosx/arduino-*.zip +build/macosx/dist/*.tar.gz +build/macosx/dist/*.tar.bz2 +build/macosx/*.tar.bz2 +build/macosx/libastylej* +build/macosx/appbundler*.jar +build/macosx/appbundler*.zip +build/macosx/appbundler +build/macosx/appbundler-1.0ea-arduino? +build/macosx/appbundler-1.0ea-arduino*.zip +build/macosx/appbundler-1.0ea-upstream*.zip +build/linux/work/ +build/linux/dist/*.tar.gz +build/linux/dist/*.tar.bz2 +build/linux/*.tgz +build/linux/*.tar.xz +build/linux/*.tar.bz2 +build/linux/*.zip +build/linux/libastylej* +build/linux/liblistSerials* +build/shared/arduino-examples* +build/shared/reference*.zip +build/shared/Edison*.zip +build/shared/Galileo*.zip +build/shared/WiFi101-Updater-ArduinoIDE-Plugin*.zip +test-bin +*.iml +.idea +.DS_Store +.directory +hardware/arduino/avr/libraries/Bridge/examples/XivelyClient/passwords.h +avr-toolchain-*.zip +/app/nbproject/private/ +/arduino-core/nbproject/private/ +/app/build/ +/arduino-core/build/ +manifest.mf +nbbuild.xml +nbproject \ No newline at end of file diff --git a/AlarmeESP32.ino b/AlarmeESP32.ino new file mode 100644 index 0000000..135694e --- /dev/null +++ b/AlarmeESP32.ino @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +volatile bool motionDetected = false; + +void IRAM_ATTR onMotionDetected() { + motionDetected = true; // Flag à traiter dans loop() +} + +void setup() { + pinMode(A2, INPUT); + pinMode(D2, OUTPUT); + attachInterrupt(digitalPinToInterrupt(A2), onMotionDetected, RISING); + + blinkSlowGreen(); +} + +void loop() { + if(motionDetected){ + Serial.println("Mouvement détecté !"); + blinkFastRed(); + startSirene(); + } + updateLed(); + updateSirene(); +} + diff --git a/FirebaseHandler.h b/FirebaseHandler.h new file mode 100644 index 0000000..e69de29 diff --git a/branchements.h b/branchements.h new file mode 100644 index 0000000..9992349 --- /dev/null +++ b/branchements.h @@ -0,0 +1,14 @@ +#define A0 26 +#define A1 25 +#define A2 34 +#define D2 39 +#define A4 36 +#define A5 4 +#define D2 14 +#define D3 32 +#define D4 15 +#define D5 33 +#define RX 16 +#define TX 17 +#define SCL 22 +#define SDA 23 \ No newline at end of file diff --git a/ctrlLed.h b/ctrlLed.h new file mode 100644 index 0000000..e55fe69 --- /dev/null +++ b/ctrlLed.h @@ -0,0 +1,64 @@ +#include +#include + +#define NUM_LEDS 1 + +ChainableLED leds(D4, D5, NUM_LEDS); + +enum LedState { OFF, FAST_RED, SLOW_RED, SLOW_GREEN }; +LedState currentState = OFF; + +unsigned long previousMillis = 0; +int blinkInterval = 0; +bool ledOn = false; + +void updateLed() { + unsigned long currentMillis = millis(); + + if (currentState == OFF) { + leds.setColorRGB(0, 0, 0, 0); // Éteindre la LED + return; + } + + if (currentMillis - previousMillis >= blinkInterval) { + previousMillis = currentMillis; + ledOn = !ledOn; // Alterner entre ON et OFF + + switch (currentState) { + case FAST_RED: + leds.setColorRGB(0, ledOn ? 255 : 0, 0, 0); + blinkInterval = 200; // Alternance rapide + break; + case SLOW_RED: + leds.setColorRGB(0, ledOn ? 255 : 0, 0, 0); + blinkInterval = ledOn ? 200 : 1300; // Court allumage, longue extinction + break; + case SLOW_GREEN: + leds.setColorRGB(0, 0, ledOn ? 255 : 0, 0); + blinkInterval = ledOn ? 200 : 800; // Court allumage, longue extinction + break; + default: + break; + } + } +} + +void blinkFastRed() { + currentState = FAST_RED; + blinkInterval = 200; +} + +void blinkSlowRed() { + currentState = SLOW_RED; + blinkInterval = 200; // Premier allumage court +} + +void blinkSlowGreen() { + currentState = SLOW_GREEN; + blinkInterval = 200; // Premier allumage court +} + +void clearLed() { + currentState = OFF; + leds.setColorRGB(0, 0, 0, 0); +} diff --git a/ctrlRfid.h b/ctrlRfid.h new file mode 100644 index 0000000..e69de29 diff --git a/ctrlSpeaker.h b/ctrlSpeaker.h new file mode 100644 index 0000000..dbb9e33 --- /dev/null +++ b/ctrlSpeaker.h @@ -0,0 +1,34 @@ +#include + +// Fréquences sirène +int sirenTab[] = {1516, 1702}; + +bool sireneOn = false; +unsigned long previousMillisAlarm = 0; // Stocke le temps écoulé +unsigned long interval = 250; // Intervalle pour changer de fréquence +int sirenIndex = 0; // Indice de la fréquence actuelle + +void updateSirene() { + if(sireneOn) { + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillisAlarm >= interval) { + // Si le temps est écoulé, change de fréquence + previousMillisAlarm = currentMillis; + + tone(D2, sirenTab[sirenIndex], 200); + + sirenIndex = (sirenIndex + 1) % 2; + } + } else { + noTone(D2); + } +} + +void startSirene() { + sireneOn = true; +} + +void stopSirene() { + sireneOn = false; +}