Sto impazzendo da giorni... cosa sbaglio?
codice sola figura su matrice:
Codice: Seleziona tutto
#include "LedControl.h"
#define DIN 0
#define CS 1
#define CLK 3
#define Moduli 1
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 sola accensione led presente su scheda esp8266:
Codice: Seleziona tutto
#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);
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 modificato da me con primo + secondo codice
Codice: Seleziona tutto
#include <ESP8266WiFi.h>
#include "LedControl.h" // led
#define DIN 0 // led
#define CS 1 // led
#define CLK 3 // led
#define Moduli 1// led
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};
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);
lc.shutdown(0, false); // led
lc.setIntensity(0, 3); // led
lc.clearDisplay(0); // led
Serial.print("Connecting to the Newtork");
WiFi.begin(ssid, password);
IPAddress ip(192, 168, 1, 171); //XXX sceglilo tu
IPAddress gateway(192, 168, 1, 1); //suppongo sia quello di default se no settalo tu
IPAddress subnet(255, 255, 255, 0); //Come sopra
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
value = HIGH;
delay (10);
Serial.println("MAtrice Accesa");
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, a[row]);
Serial.println(row);
}
delay(500);
}
if(request.indexOf("/LED=OFF") != -1)
{
digitalWrite(LED, LOW); // Turn LED OFF
value = LOW;
Serial.println("MAtrice spenta");
delay (10);
for (int row = 0; row < 8; row++) {
lc.setRow (0, row, b[row]);
Serial.println(row);
}
}
//*------------------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("");
}
QUI sono presenti la foto che illustra la matrice illuminata caricando solo il codice per l'accensione di essa e il video illustra il problema che sto riscontrando. Tramite webpage il led si controlla ma la matrice rimane sempre spenta. https://drive.google.com/drive/folders/ ... sp=sharing