/* Project: Wifi controlled LED matrix display NodeMCU pins -> EasyMatrix pins MOSI-D7-GPIO13 -> DIN CLK-D5-GPIO14 -> Clk GPIO0-D3 -> LOAD Pin Name GPIO # HSPI Function MTDI GPIO12 MISO (DIN) MTCK GPIO13 MOSI (DOUT) MTMS GPIO14 CLOCK MTDO GPIO15 CS / SS GPIO0 = 3 GPIO1 = 10 GPIO2 = 4 GPIO3 = 9 GPIO4 = 2 GPIO5 = 1 GPIO9 = 11 GPIO10 = 12 GPIO12 = 6 GPIO13 = 7 GPIO14 = 5 GPIO15 = 8 GPIO16 = 0 */ #include #include #include #include #include #include #include #include #include // Helps with connecting to internet #include // HOSTNAME for OTA update #define HOSTNAME "ESP8266-OTA-" void configModeCallback (WiFiManager *myWiFiManager); // ******************* String form to sent to the client-browser ************************************ String form = "

" "

" "

ESP8266 Web Server

" "

Type your message

" "
"; ESP8266WebServer server(80); // HTTP server will listen at port 80 long period; int offset=1,refresh=0; int pinCS = 0; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) int numberOfHorizontalDisplays = 8; int numberOfVerticalDisplays = 1; String decodedMsg; Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); String tape = "Arduino"; int wait = 80; // In milliseconds int spacer = 1; int width = 5 + spacer; // The font width is 5 pixels /* handles the messages coming from the webbrowser, restores a few special characters and constructs the strings that can be sent to the oled display */ void handle_msg() { matrix.fillScreen(LOW); server.send(200, "text/html", form); // Send same page so they can send another msg refresh=1; // Display msg on Oled String msg = server.arg("msg"); Serial.println(msg); decodedMsg = msg; // Restore special characters that are misformed to %char by the client browser decodedMsg.replace(0xc4, 0x8e); decodedMsg.replace(0xd6, 0x99); decodedMsg.replace(0xDC, 0x9A); decodedMsg.replace(0xE4, 0x84); decodedMsg.replace(0xF6, 0x94); decodedMsg.replace(0xFC, 0x81); decodedMsg.replace(0xDF, 0xE0); decodedMsg.replace(0xA7, 0x15); decodedMsg.replace("+", " "); decodedMsg.replace("%21", "!"); decodedMsg.replace("%22", ""); decodedMsg.replace("%23", "#"); decodedMsg.replace("%24", "$"); decodedMsg.replace("%25", "%"); decodedMsg.replace("%26", "&"); decodedMsg.replace("%27", "'"); decodedMsg.replace("%28", "("); decodedMsg.replace("%29", ")"); decodedMsg.replace("%2A", "*"); decodedMsg.replace("%2B", "+"); decodedMsg.replace("%2C", ","); decodedMsg.replace("%2F", "/"); decodedMsg.replace("%3A", ":"); decodedMsg.replace("%3B", ";"); decodedMsg.replace("%3C", "<"); decodedMsg.replace("%3D", "="); decodedMsg.replace("%3E", ">"); decodedMsg.replace("%3F", "?"); decodedMsg.replace("%40", "@"); Serial.println(decodedMsg); // print original string to monitor Serial.println(' '); // new line in monitor } // ---------------------------------------------------------------------------------------- void setup(void) { matrix.setIntensity(3); // Use a value between 0 and 15 for brightness // Adjust to your own needs // matrix.setPosition(0, 1, 0); // The first display is at <0, 0> // matrix.setPosition(1, 0, 0); // The second display is at <1, 0> /* // Adjust to your own needs matrix.setPosition(0, 7, 0); // The first display is at <0, 7> matrix.setPosition(1, 6, 0); // The second display is at <1, 0> matrix.setPosition(2, 5, 0); // The third display is at <2, 0> matrix.setPosition(3, 4, 0); // And the last display is at <3, 0> matrix.setPosition(4, 3, 0); // The first display is at <0, 0> matrix.setPosition(5, 2, 0); // The second display is at <1, 0> matrix.setPosition(6, 1, 0); // The third display is at <2, 0> matrix.setPosition(7, 0, 0); // And the last display is at <3, 0> */ // начальные координаты матриц 8*8 matrix.setRotation(0, 1); // 1 матрица matrix.setRotation(1, 1); // 2 матрица matrix.setRotation(2, 1); // 3 матрица matrix.setRotation(3, 1); // 4 матрица matrix.setRotation(4, 1); // 4 матрица matrix.setRotation(5, 1); // 4 матрица matrix.setRotation(6, 1); // 4 матрица matrix.setRotation(7, 1); // 4 матрица matrix.fillScreen(LOW); // clear display matrix.write(); // Send bitmap to display //ESP.wdtDisable(); // used to debug, disable wachdog timer, Serial.begin(115200); // full speed to monitor //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; // Uncomment for testing wifi manager //wifiManager.resetSettings(); wifiManager.setAPCallback(configModeCallback); //or use this for auto generated name ESP + ChipID wifiManager.autoConnect(); // OTA Setup String hostname(HOSTNAME); hostname += String(ESP.getChipId(), HEX); WiFi.hostname(hostname); ArduinoOTA.setHostname((const char *)hostname.c_str()); ArduinoOTA.begin(); while (WiFi.status() != WL_CONNECTED) { // Wait for connection delay(500); Serial.print("."); } // Set up the endpoints for HTTP server, Endpoints can be written as inline functions: server.on("/", []() { server.send(200, "text/html", form); }); server.on("/msg", handle_msg); // And as regular external functions: server.begin(); // Start the server char result[255]; sprintf(result, "WebServer ready! Send Message using http://%1d.%1d.%1d.%1d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]); Serial.println(); Serial.println(result); decodedMsg = result; Serial.println("WebServer ready! "); Serial.println(WiFi.localIP()); // Serial monitor prints localIP // Serial.print(analogRead(A0)); } // ---------------------------------------------------------------------------------------- void loop(void) { for ( int i = 0 ; i < width * decodedMsg.length() + matrix.width() - 1 - spacer; i++ ) { server.handleClient(); // checks for incoming messages if (refresh==1) i=0; refresh=0; 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 < decodedMsg.length() ) { matrix.drawChar(x, y, decodedMsg[letter], HIGH, LOW, 1); } letter--; x -= width; } matrix.write(); // Send bitmap to display delay(wait); } } // Called if WiFi has not been configured yet void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Wifi Manager"); Serial.println("Please connect to AP"); Serial.println(myWiFiManager->getConfigPortalSSID()); Serial.println("To setup Wifi Configuration"); }