Explorateur Numérique
// Inclusion des bibliothèques
#include <SoftwareSerial.h>
#include "Ultrasonic.h"
#include "Adafruit_NeoPixel.h"
#include <Arduino.h>
#include <HardwareSerial.h>
#include "DFRobot_SerialScreen771.h"
// Définition des broches et constantes
#define LED2 5
#define NUMLEDS2 10
#define PIR_PIN 6
#define ULTRASONIC_PIN 7
#define LIDAR_THRESHOLD 10
#define buttonPin 4
SoftwareSerial SerialLidar(2, 3);
SoftwareSerial afficheurLED(A0, A1);
SoftwareSerial xbee(A2, A3);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(NUMLEDS2, LED2, NEO_GRB + NEO_KHZ800);
DFRobot_SerialScreen771 screen(afficheurLED);
Ultrasonic ultrasonic(ULTRASONIC_PIN);
// Messages affichés
const char* messages[] = {
"<CGD>Aucun risque present, bonne promenade !",
"<CYL>Presence de chenilles urticantes. Restez vigilants",
"<CRD>Abattage d'arbres en cours, passage defendu !",
"<CRD>Chasse en cours, passage defendu !",
"<CDD>null"
};
void setup() {
afficheurLED.begin(19200);
SerialLidar.begin(19200);
screen.begin();
xbee.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(PIR_PIN, INPUT);
pixels2.setBrightness(100);
pixels2.begin();
for (int i = 0; i < NUMLEDS2; i++) {
pixels2.setPixelColor(i, pixels2.Color(0, 150, 0));
}
pixels2.show();
screen.setBrightness(55);
for (int i = 0; i < 5; i++) {
screen.setMessageList(screen.eBanner_1 + i, messages[i]);
}
}
void loop() {
updateDisplayWithButton();
int pirState = digitalRead(PIR_PIN);
long ultraDist = ultrasonic.MeasureInCentimeters();
int ultraState = (ultraDist > 0 && ultraDist < 100) ? 1 : 0;
int distance = getLidarDistance();
int lidarState = (abs(distance - lastLidarDist) > LIDAR_THRESHOLD) ? 1 : 0;
lastLidarDist = distance;
int totalDetected = pirState + ultraState + lidarState;
if (totalDetected >= 2) {
xbee.write(etat);
changement_couleur();
screen.displayBanner(screen.eBanner_1+ etat);
delay(3000);
} else {
for (int i = 0; i < NUMLEDS2; i++) {
pixels2.setPixelColor(i, pixels2.Color(0, 0, 0));
}
screen.displayBanner(screen.eBanner_5);
pixels2.show();
}
}
void updateDisplayWithButton() {
bool buttonState = digitalRead(buttonPin);
if (buttonState == LOW && lastButtonState == HIGH) {
lastDebounceTime = millis();
etat = (etat + 1) % 4;
changement_couleur();
delay(1000);
}
lastButtonState = buttonState;
}
void changement_couleur() {
uint32_t colors[] = {
pixels2.Color(0, 150, 0),
pixels2.Color(255, 253, 0),
pixels2.Color(255, 0, 0),
pixels2.Color(255, 0, 0)
};
for (int i = 0; i < NUMLEDS2; i++) {
pixels2.setPixelColor(i, colors[etat]);
}
pixels2.show();
}
// Inclusion des bibliothèques
#include <SoftwareSerial.h>
#include "Adafruit_NeoPixel.h"
#include <Wire.h>
#include "rgb_lcd.h"
// Création de l'objet LCD
rgb_lcd lcd;
#define LED3 5 // Petite broche
#define NUMLEDS3 10 // Nombre de LEDS
Adafruit_NeoPixel pixels3 = Adafruit_NeoPixel(NUMLEDS3, LED3, NEO_GRB + NEO_KHZ800);
int etat = 0; // État
SoftwareSerial xbee(2,3); // RX, TX pour le XBee
void setup() {
Serial.begin(9600);
xbee.begin(9600);
pixels3.setBrightness(100);
pixels3.begin();
}
void loop() {
for (int i = 0; i < NUMLEDS3; i++) {
pixels3.setPixelColor(i, pixels3.Color(0, 0, 0));
pixels3.show();
}
etat = xbee.read();
if (etat > -1) {
lcd.begin(16, 2);
changement_couleur();
switch (etat) {
case 0:
lcd.setRGB(0, 150, 0);
lcd.setCursor(0, 0);
lcd.print("Aucun risque,");
lcd.setCursor(0, 1);
lcd.print("bonne promenade !");
delay(3000);
break;
case 1:
lcd.setRGB(255, 255, 0);
lcd.print("Chenilles,");
lcd.setCursor(0, 1);
lcd.print("Restez vigilants!");
delay(3000);
break;
case 2:
case 3:
lcd.setRGB(255, 0, 0);
lcd.print("Passage interdit!");
delay(3000);
break;
}
lcd.setRGB(0, 0, 0);
lcd.noDisplay();
}
}
void changement_couleur() {
uint32_t colors[] = {
pixels3.Color(0, 150, 0),
pixels3.Color(255, 255, 0),
pixels3.Color(255, 0, 0),
pixels3.Color(255, 0, 0)
};
uint32_t color = colors[etat];
for (int i = 0; i < NUMLEDS3; i++) {
pixels3.setPixelColor(i, color);
}
pixels3.show();
}