// Header file includes
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
//#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8 // Define the number of displays connected
#define CLK_PIN 18 // CLK or SCK
#define DATA_PIN 23 // DATA or MOSI
#define CS_PIN 5 // CS or SS
#define NTP_SERVER "0.br.pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST -10890
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
LCD.setCursor(15, 1);
LCD.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
myDisplay.print("Connection Err");
LCD.setCursor(0, 0);
LCD.println("Connection Err");
return;
}
LCD.setCursor(0, 0);
LCD.println("LAB+ PROJETOS");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y-%H:%M");
myDisplay.setTextAlignment(PA_CENTER);
myDisplay.print(&timeinfo, "%H:%M");
delay(5000);
myDisplay.print(&timeinfo, "%d/%m/%Y");
delay(5000);
myDisplay.print("Lab+ Projetos");
delay(5000);
loop();
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
// Intialize the object:
myDisplay.begin();
// Set the intensity (brightness) of the display (0-15):
myDisplay.setIntensity(15);
// Clear the display:
myDisplay.displayClear();
}
void loop() {
printLocalTime();
delay(250);
}