Created
May 17, 2020 13:02
Contrôle à distance d'une matrice de LEDs 8 X 8 branchée à un ESP8266 ou ESP32.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
ESP_Matrice_LEDs | |
Contrôle d'une matrice de LEDs 8 X 8 | |
branchée à un ESP8266 ou ESP32 | |
Înformations détaillées: | |
https://electroniqueamateur.blogspot.com/2020/05/matrice-de-leds-et-esp8266-esp32.html | |
***********************************************************************/ | |
// inclusion des bibliothèques utiles | |
// pour la communication WiFi | |
#if defined ARDUINO_ARCH_ESP8266 // s'il s'agit d'un ESP8266 | |
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
#elif defined ARDUINO_ARCH_ESP32 // s'il s'agit d'un ESP32 | |
#include "WiFi.h" | |
#include <WebServer.h> | |
#endif | |
#include <WiFiClient.h> | |
#include "LedControl.h" // bibliotheque LEDControl | |
// modifiez ces deux constantes pour qu'elles contiennent les caractéristiques de | |
// votre réseau Wifi | |
#define ssid "********" // le nom (SSID) de votre réseau WiFi | |
#define password "********" // votre mot de passe WiFi | |
LedControl lc = LedControl(12, 13, 15, 1); // DIN, CLK, CS, 1 seule matrice | |
#if defined ARDUINO_ARCH_ESP8266 // s'il s'agit d'un ESP8266 | |
ESP8266WebServer server(80); | |
#elif defined ARDUINO_ARCH_ESP32 // s'il s'agit d'un ESP32 | |
WebServer server(80); | |
#endif | |
byte grille[8][8]; // tableau contenant l'état de chaque LED | |
/* La fonction construitPage retourne un string qui contient toute notre page web */ | |
String construitPage() { | |
String page = "<html lang=fr-FR><head>"; | |
page += "<title>Matrice de LEDs</title>"; | |
page += "</head><body><h1>Matrice de 64 LEDs</h1>"; | |
page +="<p> Cliquez sur les LEDs que vous désirez allumer.</p>"; | |
page += "<form action='/' method='POST'>"; | |
for (int i = 0; i <= 63; i++) { | |
page += "<INPUT type='checkbox' name='" + String(i) + "'"; | |
if (grille[i/8][i%8]){ | |
page += " checked "; | |
} | |
page += ">"; | |
if (i % 8 == 7) { | |
page += "<br>"; | |
} | |
} | |
page += "<br> <br> "; | |
page += "<INPUT type='submit' value='Appliquer'><br><br>"; | |
page += "</body></html>"; | |
return page; | |
} | |
/* La fonction gestionPage modifie l'état des LEDs | |
quand le bouton Appliquer a été cliqué. */ | |
void gestionPage() { | |
String numero; | |
for (int i = 0; i <= 63; i++) { | |
numero = String(i); | |
grille[i/8][i%8] = server.hasArg(numero); | |
} | |
gestionLEDs(); | |
server.send ( 200, "text/html", construitPage() ); | |
} | |
/* Contrôle des LEDS de la matrice 8 X 8 */ | |
void gestionLEDs() { | |
for (int ligne = 0; ligne < 8; ligne++) | |
{ | |
for (int col = 0; col < 8; col++) | |
{ | |
lc.setLed(0, ligne, col, grille[ligne][col]); | |
} | |
} | |
} | |
void setup() { | |
lc.shutdown(0, false); // interruption du mode "économie d'énergie" | |
lc.setIntensity(0, 8); // réglage d'intensité (0~15) | |
lc.clearDisplay(0);// on éteint toutes les LEDs | |
// pour affichage dans le moniteur série | |
Serial.begin ( 115200 ); | |
Serial.println(""); | |
WiFi.mode(WIFI_STA); | |
// initialisation de la communication WiFi | |
WiFi.begin ( ssid, password ); | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay ( 500 ); Serial.print ( "." ); | |
} | |
Serial.println ( "" ); | |
Serial.print ( "Maintenant connecte a " ); | |
Serial.println ( ssid ); | |
Serial.print ( "Adresse IP: " ); | |
Serial.println ( WiFi.localIP() ); | |
// On indique le nom de la fonction qui gère l'interraction avec la page web | |
server.on ( "/", gestionPage ); | |
server.begin(); | |
Serial.println ( "Serveur HTTP en fonction" ); | |
} | |
void loop() { | |
server.handleClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment