Buongiorno a tutti, sto cercando di controllare l'accensione/spegnimento di una figura sulla matrice led su una scheda esp01 attraverso una pagina web. In rete ho trovato il codice per il controllo di un led tramite webpage attraverso il tasto on/off raggiungibile da IP. Poi modificando un altro codice presente in rete ho fatto accendere sulla matrice la figura da me necessaria. Ora però nel "unire" assieme i due codici non riesco a far accendere la matrice. Si comanda sempre e solo il led e la matrice rimane spenta. Dove sbaglio? Sto impazzendo da giorni...
Codice per controllo on/off led via webpage
#include <ESP8266WiFi.h>
const char* ssid = "Wi-Fi Name"; // Your Wi-Fi Name
const char* password = "Password"; // Wi-Fi Password
int LED = 2; // led connected to GPIO2 (D4)
WiFiServer server(80); //server port
void setup() {
Serial.begin(115200); //Default Baudrate
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
Serial.print("Connecting to the Newtork");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin(); // Starts the Server
Serial.println("Server started");
Serial.print("IP Address of network: "); // will IP address on Serial Monitor
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://"); // Will print IP address in URL format
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Waiting for new client");
while(!client.available()) {
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = LOW;
if(request.indexOf("/LED=ON") != -1) {
digitalWrite(LED, HIGH); // Turn LED ON
value = HIGH;
}
if(request.indexOf("/LED=OFF") != -1) {
digitalWrite(LED, LOW); // Turn LED OFF
value = LOW;
}
//*------------------HTML Page Code---------------------*//
client.println("HTTP/1.1 200 OK"); //
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print(" CONTROL LED: ");
if(value == HIGH) {
client.print("ON");
}
else {
client.print("OFF");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>ON</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>OFF</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
codice visualizzazione immagine su matrice
#include "LedControl.h" //libreria matrice led
#define DIN 0 //dichiarazione pin matrice
#define CS 1 //dichiarazione pin matrice
#define CLK 3 //dichiarazione pin matrice
#define Moduli 1 //dichiarazione moduli matrice
LedControl lc = LedControl(DIN, CLK, CS, Moduli);
byte a[8] = {B00111100,B01111110,B11111111,B10000001,B10000001,B11111111,B01111110,B00111100};
byte b[8] = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 3);
lc.clearDisplay(0);
}
void loop() {
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, a[row]);
}
delay(2000);
for (int row = 0; row < 8; row++) {
lc.setRow (0, row, b[row]);
}
delay(500);
}
Codice non funzionante unendo i due codice precedenti
#include <ESP8266WiFi.h>
//*------------------CODICE MATRICE---------------------*//
#include "LedControl.h" //libreria matrice led
#define DIN 0 //dichiarazione pin matrice
#define CS 1 //dichiarazione pin matrice
#define CLK 3 //dichiarazione pin matrice
#define Moduli 1 //dichiarazione moduli matrice
LedControl lc = LedControl(DIN, CLK, CS, Moduli); //
byte a[8] = {B00111100,B01111110,B11111111,B10000001,B10000001,B11111111,B01111110,B00111100};
byte b[8] = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000};
//*------------------FINE CODICE MATRICE---------------------*//
const char* ssid = "wifissid"; // Your Wi-Fi Name
const char* password = "pass"; // Wi-Fi Password
int LED = 2; // led connected to GPIO2 (D4)
WiFiServer server(80);
void setup() {
Serial.begin(115200); //Default Baudrate
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
//*------------------CODICE MATRICE---------------------*//
lc.shutdown(0, false); // led
lc.setIntensity(0, 3); // led
lc.clearDisplay(0); // led
//*------------------FINE CODICE MATRICE---------------------*//
Serial.print("Connecting to the Newtork");
WiFi.begin(ssid, password);
IPAddress ip(192, 168, 1, 171); //IP STATICO
IPAddress gateway(192, 168, 1, 1); //GATEWAY ROUTER
IPAddress subnet(255, 255, 255, 0); //SUBNET ROUTER
WiFi.config(ip, gateway, subnet);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin(); // Starts the Server
Serial.println("Server started");
Serial.print("IP Address of network: "); // will IP address on Serial Monitor
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://"); // Will print IP address in URL format
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
WiFiClient client = server.available();
if (!client) {
return;
}
Serial.println("Waiting for new client");
while(!client.available()) {
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = LOW;
if(request.indexOf("/LED=ON") != -1) {
digitalWrite(LED, HIGH); // Turn LED ON (questo funziona)
value = HIGH;
delay (10);
//*------------------CODICE MATRICE---------------------*//
for (int row = 0; row < 8; row++) { //ACCENSIONE FIGURA MATRICE, non da errore ma non la accende
lc.setRow(0, row, a[row]);
}
//*------------------FINE CODICE MATRICE---------------------*//
}
if(request.indexOf("/LED=OFF") != -1) {
digitalWrite(LED, LOW); // Turn LED OFF
value = LOW;
delay (10);
//*------------------CODICE MATRICE---------------------*//
for (int row = 0; row < 8; row++) { //SPEGNIMENTO FIGURA MATRICE
lc.setRow (0, row, b[row]);
}
//*------------------FINE CODICE MATRICE---------------------*//
}
//*------------------HTML Page Code---------------------*//
client.println("HTTP/1.1 200 OK"); //
client.println("Content-Type: text/html");
client.println("");
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print(" CONTROL LED: ");
if(value == HIGH) {
client.print("ON");
}
else {
client.print("OFF");
}
client.println("<br><br>");
client.println("<a href=\"/LED=ON\"\"><button>ON</button></a>");
client.println("<a href=\"/LED=OFF\"\"><button>OFF</button></a><br />");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}