// prototype etection de proximité, interruption , affichage sur ecran oled, et leds
#include <Adafruit_SSD1306.h>
#include <Adafruit_NeoPixel.h>
#define nombreDePixelsEnLargeur 128 // Taille de l'écran OLED, en pixel, au niveau de sa largeur
#define nombreDePixelsEnHauteur 64 // Taille de l'écran OLED, en pixel, au niveau de sa hauteur
#define brocheResetOLED -1 // Reset de l'OLED partagé avec l'Arduino (d'où la valeur à -1, et non un numéro de pin)
#define adresseI2CecranOLED 0x3C // Adresse de "mon" écran OLED sur le bus i2c (généralement égal à 0x3C ou 0x3D)
Adafruit_SSD1306 ecranOLED(nombreDePixelsEnLargeur, nombreDePixelsEnHauteur, &Wire, brocheResetOLED); // instancier en suivant la classe « Adafruit_SSD1306 », pour pouvoir vous en servir par la suite. Cela se fait d’ailleurs d’une seule ligne : Adafruit_SSD1306 ecranOLED(nombreDePixelsEnLargeur, nombreDePixelsEnHauteur, &Wire, brocheResetOLED)
// Définition de la partie Led
#define LED_PIN 9 // sur quelle broche de l'arduino est connecté la led (DIN)
#define LED_COUNT 6 // Combien de led
#define Rouge (0xFF0000) // definition de la couleur rouge en Hexadécimal
// Declaration de l'objet NeoPixels strip
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Nombre de LED dans le Neopixel strip
// Argument 2 = Broche Arduino sur laquelle est branché le NeoPixel strip
// Argument 3 = Type de Ruban Led + reglage ( NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// Image à afficher
#define largeurDeLimage 128 // Largeur de l'image à afficher
#define hauteurDeLimage 64 // Hauteur de l'image à afficher
const unsigned char logo [] PROGMEM = {
// Logo NEXANS 128x64px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xe0, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xf8, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xfc, 0x00, 0x1f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0xbc, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1e, 0x1e, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1e, 0x0e, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x0e, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x07, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x07, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x07, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x07, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x03, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x03, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x03, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x03, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x01, 0xc0, 0xf0, 0x1f, 0x02, 0x03, 0x07, 0xe0, 0x1f, 0x80, 0x3f, 0x00, 0x00, 0x00,
0x00, 0x38, 0x01, 0xc0, 0xf0, 0x3f, 0x87, 0x07, 0x1f, 0xf0, 0x7f, 0xe0, 0x7f, 0x80, 0x00, 0x00,
0x00, 0x70, 0x01, 0xc0, 0xf0, 0x7f, 0xc3, 0x87, 0x1f, 0xf8, 0x7f, 0xf0, 0xff, 0x80, 0x00, 0x00,
0x00, 0x70, 0x01, 0xc0, 0xf0, 0xe1, 0xe3, 0x8e, 0x1c, 0x38, 0x70, 0x71, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x70, 0x01, 0xe0, 0xf0, 0xe0, 0xe1, 0xde, 0x00, 0x1c, 0x70, 0x71, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x70, 0x00, 0xe0, 0xf0, 0xc0, 0xe0, 0xfc, 0x00, 0x1c, 0x70, 0x39, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x70, 0x00, 0xe0, 0xe0, 0xe1, 0xe0, 0xf8, 0x07, 0xfc, 0x70, 0x38, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x70, 0x00, 0xe0, 0xe0, 0xff, 0xe0, 0x78, 0x0f, 0xfc, 0x70, 0x38, 0xff, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x70, 0xe0, 0xff, 0xe0, 0x78, 0x1f, 0xfc, 0x70, 0x38, 0x3f, 0x80, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x70, 0xe0, 0xe0, 0x00, 0xfc, 0x3c, 0x1c, 0x70, 0x38, 0x0f, 0x80, 0x00, 0x00,
0x01, 0xe0, 0x00, 0x71, 0xe0, 0xc0, 0x01, 0xfc, 0x38, 0x1c, 0x70, 0x38, 0x03, 0x80, 0x00, 0x00,
0x47, 0xc0, 0x00, 0x39, 0xe0, 0xe0, 0x03, 0xce, 0x38, 0x1c, 0x70, 0x38, 0x03, 0x80, 0x00, 0x00,
0x7f, 0x80, 0x00, 0x3f, 0xc0, 0xf0, 0xc3, 0x8f, 0x3c, 0x3c, 0x70, 0x38, 0xc3, 0x80, 0x00, 0x00,
0xff, 0x00, 0x00, 0x1f, 0xc0, 0x7f, 0xe7, 0x87, 0x1f, 0xf8, 0x70, 0x39, 0xff, 0x80, 0x00, 0x00,
0x3c, 0x00, 0x00, 0x0f, 0x00, 0x3f, 0xc7, 0x03, 0x0f, 0xf8, 0x70, 0x30, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x1c, 0xce, 0x60, 0xe8, 0x1e, 0x83, 0x07, 0x43, 0xc0, 0x73, 0x80, 0x00, 0x00,
0x00, 0x00, 0x62, 0x31, 0x04, 0xd4, 0x89, 0x0c, 0x92, 0x0c, 0x49, 0x92, 0x5a, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0x21, 0x04, 0x94, 0x86, 0x08, 0x92, 0x08, 0x48, 0x92, 0x4a, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7a, 0x3d, 0x04, 0xf4, 0xe6, 0x08, 0xf3, 0x8f, 0x48, 0x92, 0x73, 0x80, 0x00, 0x00,
0x00, 0x00, 0x42, 0x21, 0x04, 0xe4, 0x82, 0x08, 0x92, 0x08, 0x48, 0x92, 0x52, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0x21, 0x04, 0x94, 0x82, 0x08, 0x92, 0x08, 0x48, 0x92, 0x52, 0x00, 0x00, 0x00,
0x00, 0x00, 0x31, 0x9c, 0xc0, 0x00, 0x80, 0x00, 0x83, 0x00, 0x30, 0x0c, 0x03, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const int inputPin = 2; // Choix du Pin d'entrée pour le PIR ( Passif Infra Red )
int pirState = LOW; // On suppose qu'au démarrage, aucun mouvement n'est détecté
int val = 0; // Variable pour lire l'etat de u pin (broche 2)
// Déclaration de la fonction colorWipe pour le défilement des leds
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Declaration de la fonction detect ( ISR ,routine d'interruption de service )
void detect()
{
Serial.println("Changement d'etat du capteur de présence"); // affichage de l'alerte dans le moniteur serie
pirState = !pirState;
if (pirState == LOW ) {
Serial.println("Aucune présence");
}
}
void setup() {
Serial.begin(9600); // Ouverture du port série, défini le débit de donnée à 9600 Bauds
pinMode(inputPin, INPUT); // declaration du detecteur comme entrée
attachInterrupt(digitalPinToInterrupt(inputPin), detect, CHANGE); // Attache l'interruption externe à la fonction detect
// Initialisation de l'écran OLED
if (!ecranOLED.begin(SSD1306_SWITCHCAPVCC, 0x3c))
while (1); // Arrêt du programme (boucle infinie) en cas d'echec de l'initialisation
// Affichage du Logo Nexans
ecranOLED.clearDisplay(); // Effaçement de la mémoire tampon de l'écran
ecranOLED.drawBitmap(
(ecranOLED.width() - largeurDeLimage ), // Position de l'extreme "gauche" de l'image
(ecranOLED.height() - hauteurDeLimage), // Position de l'extreme "Haute" de l'image
logo,
largeurDeLimage,
hauteurDeLimage,
WHITE); // "Couleur" de l'image (white allume le pixel)
ecranOLED.display();
delay(3000);
ecranOLED.clearDisplay();
ecranOLED.display();
// Setup de la partie Led
strip.begin(); // préparation de la broche de données pour la sortie Neopixel
strip.show(); // Initialisation des pixels à l'etat 'off' ( non obligatoire mais utile pour forcer à eteindre les leds)
}
void loop() { // boucle du programme principal
if (pirState == HIGH) {
colorWipe(strip.Color(255, 0, 0), 10); // Red
colorWipe(strip.Color(255, 255, 255), 10); // white
colorWipe(strip.Color(255, 255, 0), 10); // white
tone(8, 2000, 400); // tonalité à 2kHz pendant 0.400 seconds
ecranOLED.clearDisplay(); // Effaçement de la mémoire tampon de l'écran
ecranOLED.setTextSize(2); // Taille du texte
ecranOLED.setTextColor(SSD1306_WHITE); // Couleur du texte
ecranOLED.setCursor(20, 20); // Positionnement du texte
ecranOLED.println("PRUDENCE"); // Mise en mémoire tampon du message
ecranOLED.display(); // Affichage du message
delay(400); // pause 400ms
ecranOLED.invertDisplay(true); // Inversion Black/White
ecranOLED.clearDisplay(); // vide l'écran
ecranOLED.setCursor(20, 20); // Position du curseur
ecranOLED.println("PIETONS"); // Mise en mémoire du message
ecranOLED.display(); // Affichage du message
delay(400); // pause de 400ms
ecranOLED.invertDisplay(false); // inversion Black/white (remise en par défaut(
Serial.println("Mouvement detecté"); // Affichage dans le moniteur serie
delay(200); // pause de 200ms
}
else
ecranOLED.clearDisplay(); // vide l'ecran
ecranOLED.display(); // affiche l'ecran 'vidé'
strip.clear(); // efface l'état des leds
strip.show(); // allume les leds avec ... rien ;-) => leds éteintes
}