working clock with 3 displays

This commit is contained in:
Stefan Ostermann 2021-09-17 19:35:55 +02:00
parent 3312649c01
commit cde03edb44
2 changed files with 97 additions and 82 deletions

View File

@ -27,7 +27,7 @@ void fadeIn(int max, int time, LedControl lc);
// source: https://www.best-microcontroller-projects.com/max7219.html // source: https://www.best-microcontroller-projects.com/max7219.html
// For LedControl, I have to mirror each character. // For LedControl, I have to mirror each character.
PROGMEM const unsigned char CH[] = { PROGMEM const unsigned char CH[] = {
3, 8, B0000000, B0000000, B0000000, B0000000, B0000000, // space 2, 8, B0000000, B0000000, B0000000, B0000000, B0000000, // space
1, 8, B1011111, B0000000, B0000000, B0000000, B0000000, // ! 1, 8, B1011111, B0000000, B0000000, B0000000, B0000000, // !
3, 8, B0000011, B0000000, B0000011, B0000000, B0000000, // " 3, 8, B0000011, B0000000, B0000011, B0000000, B0000000, // "
5, 8, B0010100, B0111110, B0010100, B0111110, B0010100, // # 5, 8, B0010100, B0111110, B0010100, B0111110, B0010100, // #

View File

@ -46,13 +46,23 @@ DateTime now;
#define MAX_CS D6 #define MAX_CS D6
#define MAX_DIN D7 #define MAX_DIN D7
LedControl lc = LedControl(MAX_DIN, MAX_CLK, MAX_CS, 2); LedControl lc = LedControl(MAX_DIN, MAX_CLK, MAX_CS, 3);
/* we always wait a bit between updates of the display */ /* we always wait a bit between updates of the display */
unsigned long delaytime = 500; unsigned long delaytime = 500;
char str[24];
void configModeCallback(WiFiManager *myWiFiManager); void configModeCallback(WiFiManager *myWiFiManager);
ESP8266WebServer server(80);
void handleRoot(); // function prototypes for HTTP handlers
void handleNotFound();
void handleBody();
void reconnect();
void setTime(char* timeStr);
String SendHTML();
void setup() void setup()
{ {
@ -60,16 +70,9 @@ void setup()
//WiFiManager //WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around //Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wifiManager; WiFiManager wifiManager;
//reset settings - for testing
//wifiManager.resetSettings();
//set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode
/*
wifiManager.setAPCallback(configModeCallback); wifiManager.setAPCallback(configModeCallback);
//fetches ssid and pass and tries to connect //fetches ssid and pass and tries to connect
//if it does not connect it starts an access point with the specified name //if it does not connect it starts an access point with the specified name
//here "AutoConnectAP" //here "AutoConnectAP"
@ -82,30 +85,22 @@ void setup()
delay(1000); delay(1000);
} }
//if you get here you have connected to the WiFi //if you get here you have connected to the WiFi
Serial.println("connected...yeey :)"); Serial.println("connected...yeey :)");
*/
server.on("/", handleRoot);
server.on("/set_time", handleBody);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
/* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
for (int i=0;i<lc.getDeviceCount();i++) {
lc.shutdown(0, false); lc.shutdown(i,false);
lc.shutdown(1, false); lc.setIntensity(i,8);
}
int devices = lc.getDeviceCount();
Serial.print("devices: ");
Serial.println(devices, 10);
/* Set the brightness to a medium values */
lc.setIntensity(0, 15);
lc.clearDisplay(0);
lc.setIntensity(1, 15);
lc.clearDisplay(1);
for (int i=0;i<8;i++) { for (int i=0;i<8;i++) {
lc.setDigit(1,i,8,true); lc.setDigit(1,i,8,true);
@ -174,58 +169,78 @@ void printNumber(int v)
void loop() void loop()
{ {
DateTime now = rtc.now(); server.handleClient();
setTime(str);
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
//printStringWithShift("TEST", 150, lc);
lc.setIntensity(0, 15);
char str[24];
sprintf(str, "%02d%02d", now.hour(), now.minute());
printString(str, lc); printString(str, lc);
delay(800);
/*
int dl = 500;
printChar('1',lc);
delay(dl);
printChar('2',lc);
delay(dl);
printChar('3',lc);
delay(dl);
printChar('4',lc);
delay(dl);
printChar('5',lc);
delay(dl);
printChar('6',lc);
delay(dl);
printChar('7',lc);
delay(dl);
printChar('8',lc);
delay(dl);
printChar('9',lc);
delay(dl);
printChar('0',lc);
delay(dl);
*/
/*
lc.setDigit(0,0,3,false);
lc.setDigit(0,1,2,false);
lc.setDigit(0,2,1,false);
lc.setDigit(0,3,0,false);
*/
//delay(1000);
} }
void setTime(char* timeStr) {
DateTime now = rtc.now();
sprintf(timeStr, "%02d:%02d", now.hour(), now.minute());
}
void handleRoot()
{
server.send(200, "text/html", SendHTML());
}
void handleBody() { //Handler for the body path
if (server.hasArg("hours")== false || server.hasArg("minutes")==false){ //Check if body received
server.send(200, "text/plain", "Body not received");
return;
}
uint8_t hours = atoi(server.arg("hours").c_str());
uint8_t minutes = atoi(server.arg("minutes").c_str());
DateTime now = rtc.now();
rtc.adjust(DateTime(2021, 9, 17, hours, minutes, 0));
server.send(200, "text/html", SendHTML());
}
void handleNotFound()
{
server.send(404, "text/plain", "Not found");
}
String SendHTML()
{
setTime(str);
String ptr = "<!DOCTYPE html> <html>\n";
ptr += "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr += "<title>TooManySevenSegmentsClock</title>\n";
ptr += "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr += "body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;}\n";
ptr += "p {font-size: 24px;color: #444444;margin-bottom: 10px;}\n";
ptr += "</style>\n";
ptr += "</head>\n";
ptr += "<body>\n";
ptr += "<div id=\"webpage\">\n";
ptr += "<h1>TooManySevenSegmentsClock</h1>\n";
ptr += "<p>Time: ";
ptr += "</p>";
ptr += "<form action=\"/set_time\" method=\"post\">";
ptr += " <input type=\"number\" min=\"0\" max=\"23\" id=\"hours\" value=\"";
ptr += (int)rtc.now().hour();
ptr += "\" name=\"hours\"><br><br>";
ptr += " <input type=\"number\" min=\"0\" max=\"59\" id=\"minutes\" value=\"";
ptr += (int)rtc.now().minute();
ptr += "\" name=\"minutes\"><br><br>";
ptr += " <input type=\"submit\" value=\"Submit\">";
ptr += "</form> ";
ptr += "</div>\n";
ptr += "</body>\n";
ptr += "</html>\n";
return ptr;
}