Advertisement
NittyGritty

ESP8266_MAX7219_Message_Board_No_WM.ino

Jan 23rd, 2025
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.64 KB | None | 0 0
  1. /* ESP8266 plus MAX7219 LED Matrix that displays messages revecioved via a WiFi connection using a Web Server
  2.  Provides an automous display of messages
  3.  *####################################################################################################################################  
  4.  This software, the ideas and concepts is Copyright (c) David Bird 2018. All rights to this software are reserved.
  5.  
  6.  Any redistribution or reproduction of any part or all of the contents in any form is prohibited other than the following:
  7.  1. You may print or download to a local hard disk extracts for your personal and non-commercial use only.
  8.  2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material.
  9.  3. You may not, except with my express written permission, distribute or commercially exploit the content.
  10.  4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes.
  11.  
  12.  The above copyright ('as annotated') notice and this permission notice shall be included in all copies or substantial portions of the Software and where the
  13.  software use is visible to an end-user.
  14.  
  15.  THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY
  16.  OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17.  IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18.  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19.  See more at http://www.dsbird.org.uk
  20. */
  21.  
  22. //################# LIBRARIES ##########################
  23. #include <ESP8266WiFi.h>
  24. #include <ESP8266WebServer.h>
  25. #include <SPI.h>
  26. #include <Adafruit_GFX.h>
  27. #include <Max72xxPanel.h>
  28. #include <time.h>
  29.  
  30. const char *ssid     = "xxxxxx";
  31. const char *password = "xxxxxxxxxxxxxxxxxx";
  32.  
  33. // int pinCS = D4;    // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
  34. int pinCS = 0;        // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
  35. int numberOfHorizontalDisplays = 12;
  36. int numberOfVerticalDisplays   = 1;
  37. char time_value[20];
  38. String message, webpage;
  39.  
  40. //################# DISPLAY CONNECTIONS ################
  41. // LED Matrix Pin -> ESP8266 Pin
  42. // Vcc            -> 3v  (3V on NodeMCU 3V3 on WEMOS)
  43. // Gnd            -> Gnd (G on NodeMCU)
  44. // DIN            -> D7  (Same Pin for WEMOS)
  45. // CS             -> D4  (Same Pin for WEMOS)
  46. // CLK            -> D5  (Same Pin for WEMOS)
  47.  
  48. //################ PROGRAM SETTINGS ####################
  49. String version = "v1.0";       // Version of this program
  50. ESP8266WebServer 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
  51.                                // To access server from the outside of a WiFi network e.g. ESP8266WebServer server(8266) add a rule on your Router that forwards a
  52.                                // connection request to http://your_network_ip_address:8266 to port 8266 and view your ESP server from anywhere.
  53.                                // Example http://yourhome.ip:8266 will be directed to http://192.168.0.40:8266 or whatever IP address your router gives to this server
  54. Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
  55. int wait   = 75; // In milliseconds between scroll movements
  56. int spacer = 1;
  57. int width  = 5 + spacer; // The font width is 5 pixels
  58. String SITE_WIDTH =  "1000";
  59.  
  60. void setup() {
  61.   Serial.begin(115200); // initialize serial communications
  62.   WiFi.begin(ssid, password);
  63.   Serial.print("Connecting to ");
  64.   Serial.println(ssid);
  65.   // Wait for connection
  66.   int i = 0;
  67.   while (WiFi.status() != WL_CONNECTED && i++ <= 10) {//wait 10 seconds
  68.     delay(1000);
  69.   }
  70.   if(i == 11){
  71.     Serial.print("Could not connect to network...");
  72.     while(1) delay(500);
  73.   }
  74.   Serial.println(F("Use this URL to connect: http://")); Serial.println(WiFi.localIP().toString()+"/");// Print the IP address
  75.  
  76.   //----------------------------------------------------------------------
  77.   server.on("/",GetMessage);
  78.   server.begin(); Serial.println(F("Webserver started..."));
  79.   matrix.setIntensity(2);    // Use a value between 0 and 15 for brightness
  80.  
  81.   matrix.setRotation(0, 1);  // The first display is position upside down
  82.   matrix.setRotation(1, 1);  // The first display is position upside down
  83.   matrix.setRotation(2, 1);  // The first display is position upside down
  84.   matrix.setRotation(3, 1);  // The first display is position upside down
  85.   matrix.setRotation(4, 1);  // The first display is position upside down
  86.   matrix.setRotation(5, 1);  // The first display is position upside down
  87.   matrix.setRotation(6, 1);  // The first display is position upside down
  88.   matrix.setRotation(7, 1);  // The first display is position upside down
  89.   matrix.setRotation(8, 1);  // The first display is position upside down
  90.   matrix.setRotation(9, 1);  // The first display is position upside down
  91.   matrix.setRotation(10,1);  // The first display is position upside down
  92.   matrix.setRotation(11,1);  // The first display is position upside down
  93.  
  94.   wait    = 25;
  95.   message = "Message Board (C) D.L.Bird 2017";
  96.   display_message(message); // Display the message
  97.   wait    = 50;
  98.   message = "Welcome...";
  99. }
  100.  
  101. void loop() {
  102.   server.handleClient();
  103.   display_message(message); // Display the message
  104. }
  105.  
  106. void display_message(String message){
  107.    for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
  108.     //matrix.fillScreen(LOW);
  109.     int letter = i / width;
  110.     int x = (matrix.width() - 1) - i % width;
  111.     int y = (matrix.height() - 8) / 2; // center the text vertically
  112.     while ( x + width - spacer >= 0 && letter >= 0 ) {
  113.       if ( letter < message.length() ) {
  114.         matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background OFF, reverse these to invert the display!
  115.       }
  116.       letter--;
  117.       x -= width;
  118.     }
  119.     matrix.write(); // Send bitmap to display
  120.     delay(wait/2);
  121.   }
  122. }
  123.  
  124. void GetMessage() {
  125.   webpage = ""; // don't delete this command, it ensures the server works reliably!
  126.   append_page_header();
  127.   String IPaddress = WiFi.localIP().toString();
  128.   webpage += F("<h3>Enter the message to be displayed then Enter</h3><br>");
  129.   webpage += "<form action=\"http://"+IPaddress+"\" method=\"POST\">";
  130.   webpage += F("Enter the required message text:<br><br><input type='text' size='50' name='message' value='' >");
  131.   webpage += F("</form><br/><br/>");
  132.   append_page_footer();
  133.   server.send(200, "text/html", webpage); // Send a response to the client to enter their inputs, if needed, Enter=defaults
  134.   if (server.args() > 0 ) { // Arguments were received
  135.     for ( uint8_t i = 0; i < server.args(); i++ ) {
  136.       String Argument_Name   = server.argName(i);
  137.       String client_response = server.arg(i);
  138.       if (Argument_Name == "message")    message = client_response;
  139.     }
  140.   }
  141. }
  142.  
  143. void append_page_header() {
  144.   webpage  = F("<!DOCTYPE html><html><head>"); // Change lauguage (en) as required
  145.   webpage += F("<meta http-equiv='refresh' content='60'/>"); // 60-sec refresh time
  146.   webpage += F("<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>");
  147.   webpage += F("<title>Message Board</title><style>");
  148.   webpage += F("body {width:");
  149.   webpage += SITE_WIDTH;
  150.   webpage += F("px;margin:0 auto;font-family:arial;font-size:14px;text-align:center;color:#cc66ff;background-color:#F7F2Fd;}");
  151.   webpage += F("ul{list-style-type:none;margin:0;padding:0;overflow:hidden;background-color:#d8d8d8;font-size:14px;}");
  152.   webpage += F("li{float:left;border-right:1px solid #bbb;}last-child {border-right:none;}");
  153.   webpage += F("li a{display: block;padding:2px 12px;text-decoration:none;}");
  154.   webpage += F("li a:hover{background-color:#FFFFFF;}");
  155.   webpage += F("section {font-size:16px;}");
  156.   webpage += F("p {background-color:#E3D1E2;font-size:16px;}");
  157.   webpage += F("div.header,div.footer{padding:0.5em;color:white;background-color:gray;clear:left;}");
  158.   webpage += F("h1{background-color:#d8d8d8;font-size:26px;}");
  159.   webpage += F("h2{color:#9370DB;font-size:22px;line-height:65%;}");
  160.   webpage += F("h3{color:#9370DB;font-size:16px;line-height:55%;}");
  161.   webpage += F("table{font-family:arial,sans-serif;font-size:16px;border-collapse:collapse;width:100%;height:100%;}");
  162.   webpage += F("td {border:0px solid black;text-align:center;padding:2px;}");
  163.   webpage += F("th {border:0px solid black;text-align:center;padding:2px;font-size:22px;}");
  164.   webpage += F(".style1 {text-align:center;font-size:50px;background-color:#D8BFD8;height:57px;}");
  165.   webpage += F(".style2 {text-align:center;font-size:16px;background-color:#ADD8E6;color:#0066ff;height:25px;}");
  166.   webpage += F(".style3 {text-align:center;font-size:78px;background-color:#FFE4B5;height:107px;}");
  167.   webpage += F(".style4 {text-align:center;font-size:16px;background-color:#FFE4B5;height:30px;}");
  168.   webpage += F(".style5 {text-align:center;font-size:20px;background-color:#D9BFD9;}");
  169.   webpage += F(".style6 td {border:0px solid black;text-align:right;padding:0px;font-size:14px;background-color:#B0C4DE;color:#0066ff;height:20px;}");
  170.   webpage += F(".style7 {text-align:center;font-size:12px;background-color:#F7F2Fd;width:100%;}");
  171.   webpage += F(".style8 {text-align:center;border:0px solid black;padding:2px;color:#990099;}");
  172.   webpage += F(".style9 {text-align:center;font-size:14px;color:blue;}");
  173.   webpage += F("img.imgdisplay {display:block;margin-left:auto;margin-right:auto;}");
  174.   webpage += F("sup {vertical-align:super;font-size:26px;}");
  175.   webpage += F("sup1{vertical-align:super;font-size:10px;}");
  176.   webpage += F("</style></head><body><h1>Message Display Board ");
  177.   webpage += version+"</h1>";
  178. }
  179.  
  180. void append_page_footer(){ // Saves repeating many lines of code for HTML page footers
  181.   webpage += F("<ul><li><a href='/'>Enter Message</a></li></ul>");
  182.   webpage += "&copy;"+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)));
  183.   webpage += String(char((0x84>>1)))+String(char(byte(0xd2>>1)))+String(char(0xe4>>1))+String(char(0xc8>>1))+String(char(byte(0x40>>1)));
  184.   webpage += String(char(byte(0x64/2)))+String(char(byte(0x60>>1)))+String(char(byte(0x62>>1)))+String(char(0x6e>>1))+"</div>";
  185.   webpage += F("</body></html>");
  186. }
  187.  
Tags: ESP8266
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement