// Simple text scroller project with Web server configuration
// Author: Csongor Varga
// Github: https://github.com/nygma2004/max7219scroller
// Using the MAX7219 library of:
// MAX7219_Dot_Matrix library - sideways scrolling
// Author: Nick Gammon
// Date: 2 October 2015
/*
Used: C:\Users\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WebServer // https://github.com/esp8266/ESPWebServer
Used: C:\Users\\Documents\Arduino\libraries\MAX7219_Dot_Matrix-master // https://github.com/nickgammon/MAX7219_Dot_Matrix
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WiFi
Using library ESP8266WebServer at version 1.0 in folder: C:\Users\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266WebServer
Using library ESP8266mDNS at version 1.2 in folder: C:\Users\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\ESP8266mDNS
Using library SPI at version 1.0 in folder: C:\Users\\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.0\libraries\SPI
Using library bitBangedSPI-master in folder: C:\Users\\Documents\Arduino\libraries\bitBangedSPI-master (legacy) // https://github.com/nickgammon/bitBangedSPI
Using library MAX7219_Dot_Matrix-master at version 1.0.1 in folder: C:\Users\\Documents\Arduino\libraries\MAX7219_Dot_Matrix-master // https://github.com/nickgammon/MAX7219_Dot_Matrix
*/
//VCC Blue - Vin on the NodeMCU, 5V on Wemos D1 mini
//GND Purple - GND
//DIN Grey - D7
//CS White - D4 (this can be a different pin too)
//CLK Black - D5
#include // ESP8266 Wifi library
#include // Web server functions
#include // Web server functions
#include
#include
#include
#include
const byte chips = 4; // Number of 8x8 modules linked together
const int msglen = 500; // Maximum length of the message
// Set your wifi credetials here, for open wifi leave password empty
const char* ssid = "your ssid";
const char* password = "your password";
// You can comment this section out for using DHCP
//IPAddress ip(192, 168, 1, 85); // where xx is the desired IP Address
//IPAddress gateway(192, 168, 1, 254); // set gateway to match your network
//IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network
// n chips (display modules), hardware SPI with load on GPIO2
MAX7219_Dot_Matrix display (chips, 2); // Chips / LOAD
WiFiClient espClient;
MDNSResponder mdns;
ESP8266WebServer server(80);
char message [msglen] = "Visit website to customize";
unsigned long lastMoved = 0;
unsigned long MOVE_INTERVAL = 40; // Default delay in miliseconds
byte intensity = 4; // Default intensity 0-15
int messageOffset;
String webPage = "";
String webStat = "";
String webFooter = "";
String temp = "";
void setup() {
Serial.begin(115200);
display.begin();
display.setIntensity(intensity);
display.sendSmooth ("", 0);
// WiFi.config(ip, gateway, subnet); // Comment this line for using DHCP
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
temp = "Visit http://";
temp += WiFi.localIP().toString();
temp +=" to customize";
temp.toCharArray(message, msglen);
Serial.print("Signal [RSSI]: ");
Serial.println(WiFi.RSSI());
if (mdns.begin("max7219_display", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", handleMainPage);
server.on("/set", handleSetCommand); // Handling parameter set
server.on("/message", getMessage); // Get current Message in Json *Marcus Ferl*
server.begin();
Serial.println("HTTP server started");
messageOffset = - chips * 8;
} // end of setup
void handleMainPage() {
webPage = "MAX7219 Display and Text Scroller
This sketch scrolls a custom message on a MAX7219 driven 8x8 pixel display units chained one after the other.
";
webPage += "Change text
Current text: ";
webPage += message;
webPage += "
";
webPage += "Change scroll speed
Current delay: ";
webPage += MOVE_INTERVAL;
webPage += "
Change to: 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 100";
webPage += "
";
webPage += "Change brightness
Current brightness: ";
webPage += intensity;
webPage += "
Change to: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15";
webPage += "
";
webStat = "RSSI: ";
webStat += WiFi.RSSI();
webStat += "
";
webStat += "Uptime [min]: ";
webStat += millis() / (1000*60);
webStat += "
";
webFooter = "MAX7219 Text Scroller v1.0 | email me | GitHub
";
server.send(200, "text/html", webPage+webStat+webFooter);
Serial.println("Web page request");
}
void getMessage(){
String page;
StaticJsonBuffer<500> jsonBuffer;
JsonObject& jmessage = jsonBuffer.createObject();
jmessage["message"] = message;
jmessage.printTo(page);
server.send(200, "text/html", page);
}
void handleSetCommand() {
String response = "";
if (server.args() == 0) {
response = "No parameter";
} else {
if (server.argName(0) == "delay") {
MOVE_INTERVAL = server.arg("delay").toInt();
response = "Delay updated to ";
response += MOVE_INTERVAL;
}
if (server.argName(0) == "intensity") {
intensity = (byte)server.arg("intensity").toInt();
response = "Intensity updated to ";
display.setIntensity(intensity);
response += intensity;
}
if (server.argName(0) == "text") {
server.arg("text").toCharArray(message, msglen);
messageOffset = - chips * 8;
response = "Message updated";
}
if (response == "" ) {
response = "invalid parameter";
}
}
Serial.print("Change request: ");
Serial.println(response);
response = "" + response + "";
server.send(200, "text/html", response); //Returns the HTTP response
}
void updateDisplay() {
display.sendSmooth (message, messageOffset);
// next time show one pixel onwards
if (messageOffset++ >= (int) (strlen (message) * 8))
messageOffset = - chips * 8;
} // end of updateDisplay
void loop() {
// update display if time is up
if (millis () - lastMoved >= MOVE_INTERVAL) {
updateDisplay ();
lastMoved = millis ();
}
// Handle HTTP server requests
server.handleClient();
} // end of loop