คำตอบที่ได้รับเลือกจากเจ้าของกระทู้
ความคิดเห็นที่ 1
ปกติโปรแกรมใส่ข้อมูลมักจะไม่รองรับการส่งข้อมูล realtime นิครับ อาจจะต้อง custom นะ
ถ้าเอาหลักการก็คงต้องไปดึงข้อมูล rest api อัตราแลกเปลี่ยนก่อน แล้วให้โปรแกรมป้ายไฟ ledดึงข้อมูลจากนั้น
ต้องใช้ป้ายไฟที่รับข้อมูลระบบ wifi นะครับ
เว็บบริการข้อมูลอัตราแลกเปลี่ยน
https://exchangeratesapi.io/documentation/
ตัวอย่างโค้ด led board
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
//################# LIBRARIES ##########################
#include <WiFi.h>
#include "ESPAsyncWebServer.h" // Built-in
int pinCS = 5; // Attach CS to this pin, DIN to MOSI and CLK to SCK
// MOSI = 23; // Attach MOSI on display to this pin
// CLK = 18; // Attach CLK on display to this pin
#include <DNSServer.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
char time_value[20];
String message, webpage;
//################# DISPLAY CONNECTIONS ################
// LED Matrix Pin -> ESP8266 Pin
// Vcc -> 3v (3V3 on ESP32)
// Gnd -> Gnd (Gnd/G on ESP32)
// DIN -> MOSI
// CS -> pinCS
// CLK -> CLK
//################ PROGRAM SETTINGS ####################
String version = "v3.0"; // Version of this program
AsyncWebServer server(80); // Start server on port 80 (default for a web-browser, change to your requirements, e.g. 8080 if your Router uses port 80
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
int wait = 75; // In milliseconds between scroll movements
int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
String SITE_WIDTH = "1000";
void setup() {
Serial.begin(115200); // initialize serial communications
while(!Serial);
Serial.println("Starting...");
//The network established by softAP will have default IP address of 192.168.4.1. This address may be changed using softAPConfig.
IPAddress local_IP(192, 168, 4, 1); // Use the same adress here as defualt softAP
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
Serial.print("\rSetting soft-AP configuration ... ");
// Create SoftAP
Serial.println(WiFi.softAP("MessageBoard", "") ? "Ready" : "Failed!"); // No Password set!
Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
Serial.println("Now connect to this new Access Point, by searching for the SSID: 'MessageBoard' then connect to it");
Serial.print(F("Use this URL to connect: http://")); Serial.println(WiFi.softAPIP().toString() + "/"); // Print the IP address
//----------------------------------------------------------------------
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
GetMessage();
request->send(200, "text/html", webpage);
});
server.on("/getmessageinput", HTTP_GET, [](AsyncWebServerRequest * request) {
message = request->arg("message");
request->redirect("/");
});
server.begin(); Serial.println(F("Webserver started..."));
matrix.setIntensity(2); // Use a value between 0 and 15 for brightness
matrix.setRotation(0, 1); // The first display is position upside down
matrix.setRotation(1, 1); // The first display is position upside down
matrix.setRotation(2, 1); // The first display is position upside down
matrix.setRotation(3, 1); // The first display is position upside down
wait = 25;
message = "Message Board (C) D.L.Bird 2020";
display_message(message); // Display the message
wait = 50;
message = "Welcome...";
}
void loop() {
display_message(message); // Display the message
}
void display_message(String message) {
Serial.println(message);
for ( int i = 0 ; i < width * (int)message.length() + matrix.width() - spacer; i++ ) {
//matrix.fillScreen(LOW);
int letter = i / width;
int x = (matrix.width() - 1) - i % width;
int y = (matrix.height() - 8) / 2; // center the text vertically
while ( x + width - spacer >= 0 && letter >= 0 ) {
if ( letter < (int)message.length() ) {
matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
}
letter--;
x -= width;
}
matrix.write(); // Send text to display
delay(wait / 2);
}
}
void GetMessage() {
webpage = ""; // don't delete this command, it ensures the server works reliably!
append_page_header();
webpage += F("<h3>Enter the message to be displayed then Enter</h3><br>");
webpage += "<FORM action='getmessageinput'>";
webpage += F("Enter the required message text:<br><br><input type='text' size='50' name='message' value='' >");
webpage += F("</form><br/><br/>");
append_page_footer();
}
void append_page_header() {
webpage = "<!DOCTYPE html><html lang='en'>";
webpage += "<head>";
webpage += "<title>Message Board</title>";
webpage += "<meta charset='UTF-8'>";
webpage += "<meta http-equiv='refresh' content='60'>"; // 60-secs refresh time
webpage += "<style>";
webpage += "body {width:";
webpage += SITE_WIDTH;
webpage += "px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#cc66ff;background-color:#F7F2Fd;}";
webpage += "ul{list-style-type:none;margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}";
webpage += "li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}";
webpage += "li a{display: block;padding:2px 12px;text-decoration:none;}";
webpage += "li a:hover{background-color:#FFFFFF;}";
webpage += "section {font-size:16px;}";
webpage += "p {background-color:#E3D1E2;font-size:16px;}";
webpage += "div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}";
webpage += "h1{background-color:#d8d8d8;font-size:26px;}";
webpage += "h2{color:#9370DB;font-size:22px;line-height:65%;}";
webpage += "h3{color:#9370DB;font-size:16px;line-height:55%;}";
webpage += "</style></head><body><h1>Message Display Board ";
webpage += version + "</h1>";
}
void append_page_footer() { // Saves repeating many lines of code for HTML page footers
webpage += F("<ul><li><a href='/'>Enter Message</a></li></ul>");
webpage += "©" + String(char(byte(0x40 >> 1))) + String(char(byte(0x88 >> 1))) + String(char(byte(0x5c >> 1))) + String(char(byte(0x98 >> 1))) + String(char(byte(0x5c >> 1)));
webpage += String(char((0x84 >> 1))) + String(char(byte(0xd2 >> 1))) + String(char(0xe4 >> 1)) + String(char(0xc8 >> 1)) + String(char(byte(0x40 >> 1)));
webpage += String(char(byte(0x64 / 2))) + String(char(byte(0x60 >> 1))) + String(char(byte(0x64 >> 1))) + String(char(0x60 >> 1));
webpage += F("</body></html>");
}
ถ้าเอาหลักการก็คงต้องไปดึงข้อมูล rest api อัตราแลกเปลี่ยนก่อน แล้วให้โปรแกรมป้ายไฟ ledดึงข้อมูลจากนั้น
ต้องใช้ป้ายไฟที่รับข้อมูลระบบ wifi นะครับ
เว็บบริการข้อมูลอัตราแลกเปลี่ยน
https://exchangeratesapi.io/documentation/
ตัวอย่างโค้ด led board
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้
//################# LIBRARIES ##########################
#include <WiFi.h>
#include "ESPAsyncWebServer.h" // Built-in
int pinCS = 5; // Attach CS to this pin, DIN to MOSI and CLK to SCK
// MOSI = 23; // Attach MOSI on display to this pin
// CLK = 18; // Attach CLK on display to this pin
#include <DNSServer.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
char time_value[20];
String message, webpage;
//################# DISPLAY CONNECTIONS ################
// LED Matrix Pin -> ESP8266 Pin
// Vcc -> 3v (3V3 on ESP32)
// Gnd -> Gnd (Gnd/G on ESP32)
// DIN -> MOSI
// CS -> pinCS
// CLK -> CLK
//################ PROGRAM SETTINGS ####################
String version = "v3.0"; // Version of this program
AsyncWebServer server(80); // Start server on port 80 (default for a web-browser, change to your requirements, e.g. 8080 if your Router uses port 80
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
int wait = 75; // In milliseconds between scroll movements
int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels
String SITE_WIDTH = "1000";
void setup() {
Serial.begin(115200); // initialize serial communications
while(!Serial);
Serial.println("Starting...");
//The network established by softAP will have default IP address of 192.168.4.1. This address may be changed using softAPConfig.
IPAddress local_IP(192, 168, 4, 1); // Use the same adress here as defualt softAP
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
Serial.print("\rSetting soft-AP configuration ... ");
// Create SoftAP
Serial.println(WiFi.softAP("MessageBoard", "") ? "Ready" : "Failed!"); // No Password set!
Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
Serial.println("Now connect to this new Access Point, by searching for the SSID: 'MessageBoard' then connect to it");
Serial.print(F("Use this URL to connect: http://")); Serial.println(WiFi.softAPIP().toString() + "/"); // Print the IP address
//----------------------------------------------------------------------
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
GetMessage();
request->send(200, "text/html", webpage);
});
server.on("/getmessageinput", HTTP_GET, [](AsyncWebServerRequest * request) {
message = request->arg("message");
request->redirect("/");
});
server.begin(); Serial.println(F("Webserver started..."));
matrix.setIntensity(2); // Use a value between 0 and 15 for brightness
matrix.setRotation(0, 1); // The first display is position upside down
matrix.setRotation(1, 1); // The first display is position upside down
matrix.setRotation(2, 1); // The first display is position upside down
matrix.setRotation(3, 1); // The first display is position upside down
wait = 25;
message = "Message Board (C) D.L.Bird 2020";
display_message(message); // Display the message
wait = 50;
message = "Welcome...";
}
void loop() {
display_message(message); // Display the message
}
void display_message(String message) {
Serial.println(message);
for ( int i = 0 ; i < width * (int)message.length() + matrix.width() - spacer; i++ ) {
//matrix.fillScreen(LOW);
int letter = i / width;
int x = (matrix.width() - 1) - i % width;
int y = (matrix.height() - 8) / 2; // center the text vertically
while ( x + width - spacer >= 0 && letter >= 0 ) {
if ( letter < (int)message.length() ) {
matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
}
letter--;
x -= width;
}
matrix.write(); // Send text to display
delay(wait / 2);
}
}
void GetMessage() {
webpage = ""; // don't delete this command, it ensures the server works reliably!
append_page_header();
webpage += F("<h3>Enter the message to be displayed then Enter</h3><br>");
webpage += "<FORM action='getmessageinput'>";
webpage += F("Enter the required message text:<br><br><input type='text' size='50' name='message' value='' >");
webpage += F("</form><br/><br/>");
append_page_footer();
}
void append_page_header() {
webpage = "<!DOCTYPE html><html lang='en'>";
webpage += "<head>";
webpage += "<title>Message Board</title>";
webpage += "<meta charset='UTF-8'>";
webpage += "<meta http-equiv='refresh' content='60'>"; // 60-secs refresh time
webpage += "<style>";
webpage += "body {width:";
webpage += SITE_WIDTH;
webpage += "px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#cc66ff;background-color:#F7F2Fd;}";
webpage += "ul{list-style-type:none;margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}";
webpage += "li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}";
webpage += "li a{display: block;padding:2px 12px;text-decoration:none;}";
webpage += "li a:hover{background-color:#FFFFFF;}";
webpage += "section {font-size:16px;}";
webpage += "p {background-color:#E3D1E2;font-size:16px;}";
webpage += "div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}";
webpage += "h1{background-color:#d8d8d8;font-size:26px;}";
webpage += "h2{color:#9370DB;font-size:22px;line-height:65%;}";
webpage += "h3{color:#9370DB;font-size:16px;line-height:55%;}";
webpage += "</style></head><body><h1>Message Display Board ";
webpage += version + "</h1>";
}
void append_page_footer() { // Saves repeating many lines of code for HTML page footers
webpage += F("<ul><li><a href='/'>Enter Message</a></li></ul>");
webpage += "©" + String(char(byte(0x40 >> 1))) + String(char(byte(0x88 >> 1))) + String(char(byte(0x5c >> 1))) + String(char(byte(0x98 >> 1))) + String(char(byte(0x5c >> 1)));
webpage += String(char((0x84 >> 1))) + String(char(byte(0xd2 >> 1))) + String(char(0xe4 >> 1)) + String(char(0xc8 >> 1)) + String(char(byte(0x40 >> 1)));
webpage += String(char(byte(0x64 / 2))) + String(char(byte(0x60 >> 1))) + String(char(byte(0x64 >> 1))) + String(char(0x60 >> 1));
webpage += F("</body></html>");
}
▼ กำลังโหลดข้อมูล... ▼
แสดงความคิดเห็น
คุณสามารถแสดงความคิดเห็นกับกระทู้นี้ได้ด้วยการเข้าสู่ระบบ
รบกวนผู้รู้เเนะนำวิธีจะได้มาซึ่ง "หน้าจอเเสดงผลอัตราเเลกเปลี่ยนเเบบ real time มาติดที่หน้าบริษัท"