ОБНОВЛЕНИЕ: Мы все еще сталкиваемся с этой проблемой, но я обновил код ниже
У меня возникают некоторые проблемы, когда я хочу отобразить некоторые сообщения с помощью моей матрицы светодиодов DMD.
Этот GIF показывает, что происходит:
Я хочу оставить свет включенным и просто обновить значение под текстом.
Obs.: DMD2 - это библиотека, которую я использую для отображения своих сообщений с помощью китайской светодиодной матрицы.
Вы можете увидеть код ниже:
#include <SPI.h>
#include <DMD2.h>
#include <fonts/Arial_Black_16.h>
#include "WiFiEsp.h"
#include "ArduinoJson.h"
//http://35.198.41.210:8080/perguntometro
const int WIDTH = 3; //number of panels wide
const uint8_t *FONT = Arial_Black_16;
SoftDMD dmd(WIDTH, 1);
DMD_TextBox box(dmd);
char ssid[] = "Cubo-Residentes"; // your network SSID (name)
char pass[] = "Welcome2Cubao"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "35.198.41.210";
char buffer[255];
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 100; // delay between updates, in milliseconds
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// initialize serial for debugging
Serial.begin(9600);
// initialize serial for ESP module
Serial2.begin(115200);
// initialize ESP module
WiFi.init(&Serial2);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("You're connected to the network");
printWifiStatus();
}
void loop()
{
// if there's incoming data from the net connection send it out the serial port
// this is for debugging purposes only
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if 10 seconds have passed since your last connection,
// then connect again and send data
if (millis() - lastConnectionTime > postingInterval) {
httpRequest();
}
}
// this method makes a HTTP connection to the server
void httpRequest()
{
Serial.println();
// close any connection before send a new request
// this will free the socket on the WiFi shield
client.stop();
// if there's a successful connection
if (client.connect(server, 8080)) {
Serial.println("Connecting...");
// send the HTTP PUT request
client.println(F("GET http://35.198.41.210:8080/perguntometro"));
while (!client.available()) {}
int a = client.read(buffer, 255);
const size_t bufferSize = JSON_OBJECT_SIZE(2) + 50;
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.parseObject(buffer);
long int count = root["questionCount"];
Serial.print("Count:");
Serial.println(count);
dmd.setBrightness(255);
dmd.selectFont(FONT);
dmd.begin();
char buf[40];
dmd.drawString(1, 1, format(count, buf, 10));
delay(3000);
dmd.end();
// note the time that the connection was made
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection
Serial.println("Connection failed");
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
char *recursive(unsigned long val, char *s, unsigned radix, int pos)
{
int c;
if (val >= radix)
s = recursive(val / radix, s, radix, pos + 1);
c = val % radix;
c += (c < 10 ? '0' : 'a' - 10);
*s++ = c;
if (pos % 3 == 0) *s++ = '.';
return s;
}
char *format(long val, char *s, int radix)
{
if (radix < 2 || radix > 36) {
s[0] = 0;
} else {
char *p = s;
if (radix == 10 && val < 0) {
val = -val;
*p++ = '-';
}
p = recursive(val, p, radix, 0) - 1;
*p = 0;
}
return s;
}