ps. Is there anyway to post a video ?
Code: Select all
#include <Adafruit_Protomatter.h>
#include <Fonts/FreeSansBold18pt7b.h> // Large friendly font
#include <Fonts/FreeSerifItalic9pt7b.h>
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include "secrets.h"
//more colors at http://www.barth-dev.de/online/rgb565-color-picker/
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#if defined(_VARIANT_MATRIXPORTAL_M4_) // MatrixPortal M4
uint8_t rgbPins[] = {7, 8, 9, 10, 11, 12};
uint8_t addrPins[] = {17, 18, 19, 20, 21};
uint8_t clockPin = 14;
uint8_t latchPin = 15;
uint8_t oePin = 16;
#endif
Adafruit_Protomatter matrix(
64, // Width of matrix (or matrices, if tiled horizontally)
6, // Bit depth, 1-6
1, rgbPins, // # of matrix chains, array of 6 RGB pins for each
4, addrPins, // # of address pins (height is inferred), array of pins
clockPin, latchPin, oePin, // Other matrix control pins
true, // No double-buffering here (see "doublebuffer" example)
-2); // Row tiling: two rows in "serpentine" path
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
void setup(void) {
Serial.begin(9600);
// Connect to Wi-Fi network
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Initialize matrix...
ProtomatterStatus status = matrix.begin();
Serial.print("Protomatter begin() status: ");
Serial.println((int)status);
if(status != PROTOMATTER_OK) {
// DO NOT CONTINUE if matrix setup encountered an error.
for(;;);
}
// Set up time client
timeClient.begin();
timeClient.setTimeOffset(10800); // set the time zone offset (in seconds) from UTC
// matrix.setCursor(10, 32); // set the cursor position
// matrix.setTextColor(BLUE); // set the text color
// matrix.println("ADAFRUIT"); // print the text
// matrix.show(); // and show it
//delay(5000);
//Serial.println("TEST");
}
void loop(void) {
// Update time from NTP server
timeClient.update();
// Format the time as a string in 12-hour format
String formattedTime = timeClient.getFormattedTime();
int hour = timeClient.getHours();
if (hour > 12) {
hour = hour - 12;
} else if (hour == 0) {
hour = 12;
}
formattedTime = String(hour) + timeClient.getFormattedTime().substring(2);
// Display the time on the matrix display
matrix.fillScreen(0); // clear the screen
matrix.setCursor(5, 15); // set the cursor position
matrix.setFont(&FreeSerifItalic9pt7b); // Use nice bitmap font
matrix.setTextColor(RED); // set the text color
matrix.print(formattedTime); // print the time
matrix.show(); // and show it
delay(1000); // wait for one second before updating
}