1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include <WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Adafruit_NeoPixel.h>
#define sortie 5
#define nb_led 30
Adafruit_NeoPixel module = Adafruit_NeoPixel(nb_led, sortie,NEO_RGB + NEO_KHZ400 );
int capteur = 0;
int detection = 0;
int i = 0;
int det = 0;
int capteur2 = 0;
int detection2 = 0;
const char* ssid = "xxxxxxx";
const char* password = "xxxxxxxxxxxxxxxxxxxx";
String hostname ="Gestionnaire_LED";
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.setHostname(hostname.c_str());
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.print("Adresse mac : ");
Serial.println(WiFi.macAddress());
ArduinoOTA.setHostname("monEsp");
ArduinoOTA.begin(); // initialisation de l'OTA
// ArduinoOTA.setPassword((const char*)"1234");
}
void setup() {
Serial.begin(115200);
initWiFi();
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());
module.begin();
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
capteur = 0;
}
void loop() {
ArduinoOTA.handle();
detection = digitalRead(25);
detection2 = digitalRead(26);
if (detection == HIGH || detection2 == HIGH) {
Serial.println("Mouvement detecté !!");
if ( detection2 == HIGH) {
det = 1;
} else {
det = 0; }
Serial.print("PIR 1: ");
Serial.print(detection);
Serial.print(" PIR 2: ");
Serial.println(detection2);
if ( detection == HIGH) {
for(int i=0;i<30;i++) //boucle for
{
module.setPixelColor(i,255,0,0);
module.show();
delay (500);
}
delay(2000); //
} else {
for(int i=30;i > -1;i--) //boucle for
{
module.setPixelColor(i,255,0,0);
module.show();
delay (500);
}
delay(2000); // Wait for 1000 millisecond(s)
}} else {
Serial.println("Rien à signaler");
Serial.println("det :");
Serial.println(det);
if ( det == 1) {
for(int i=30;i > -1;i--)
{
module.setPixelColor(i,0, 0,0); //éteint
module.show();
delay (200);
}
// delay(300); //
det = 0;
} else {
for(int i=0;i< 30;i++)
{
module.setPixelColor(i,0, 0,0); //éteint
module.show();
delay (200);
}
delay(300); //
}
// delay(100); //
}
} |