Detection OK, changement couleur LED et alarme sonore OK

This commit is contained in:
PC-PAUL\paulf 2025-03-07 12:17:17 +01:00
parent 4e0cfbe12f
commit 57de082e7e
7 changed files with 211 additions and 33 deletions

102
.gitignore vendored
View File

@ -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

30
AlarmeESP32.ino Normal file
View File

@ -0,0 +1,30 @@
#include <ctrlLed.h>
#include <FireBaseHandler.h>
#include <ctrlSpeaker.h>
#include <ctrlRfid.h>
#include <branchements.h>
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();
}

0
FirebaseHandler.h Normal file
View File

14
branchements.h Normal file
View File

@ -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

64
ctrlLed.h Normal file
View File

@ -0,0 +1,64 @@
#include <ChainableLED.h>
#include <branchements.h>
#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);
}

0
ctrlRfid.h Normal file
View File

34
ctrlSpeaker.h Normal file
View File

@ -0,0 +1,34 @@
#include <Arduino.h>
// 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;
}