53 lines
1.1 KiB
C++
Executable File
53 lines
1.1 KiB
C++
Executable File
#include <RCSwitch.h>
|
|
#define couloir 12449942
|
|
#define porte 13464924
|
|
|
|
RCSwitch mySwitch = RCSwitch();
|
|
|
|
// On limite à un évènement par seconde long
|
|
#define debounceDelay 1000
|
|
|
|
// On a deux détecteurs, donc on a deux timers.
|
|
int last_times[2] = {0,0};
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
mySwitch.enableReceive(0);
|
|
}
|
|
|
|
bool debounce(int number) {
|
|
if ((last_times[number] == 0) ||
|
|
((millis() - last_times[number]) > debounceDelay)) {
|
|
last_times[number] = millis();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void loop() {
|
|
if (mySwitch.available()) {
|
|
|
|
int value = mySwitch.getReceivedValue();
|
|
|
|
// on remet à zero le timer
|
|
while (!Serial) ;
|
|
|
|
switch (value) {
|
|
case porte:
|
|
if (debounce(0))
|
|
Serial.println("Quelqu'un a ouvert la porte !");
|
|
break;
|
|
case couloir:
|
|
if (debounce(1))
|
|
Serial.println("Quelqu'un marche dans le couloir !");
|
|
break;
|
|
default:
|
|
Serial.print("Dispositif inconnu: ");
|
|
Serial.println(value);
|
|
break;
|
|
}
|
|
|
|
mySwitch.resetAvailable();
|
|
}
|
|
}
|