Created
June 12, 2018 03:26
-
-
Save sirmo/d1006c1cd1c8802c836813164830faab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WiFi.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include "Adafruit_LEDBackpack.h" | |
#ifndef _BV | |
#define _BV(bit) (1<<(bit)) | |
#endif | |
//Adafruit_LEDBackpack matrix = Adafruit_LEDBackpack(); | |
Adafruit_7segment matrix = Adafruit_7segment(); | |
const char* ssid = "your_ssid"; | |
const char* password = "pass"; | |
/* Time Stamp */ | |
#include <NTPClient.h> | |
#include <WiFiUdp.h> | |
#define NTP_OFFSET -4 * 60 * 60 // In seconds | |
#define NTP_INTERVAL 60 * 1000 // In miliseconds | |
#define NTP_ADDRESS "0.pool.ntp.org" | |
WiFiUDP ntpUDP; | |
NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET, NTP_INTERVAL); | |
uint8_t counter = 0; | |
bool dots = false; | |
void setup() | |
{ | |
Serial.begin(115200); | |
Serial.println(""); | |
Serial.println("Time Stamp example"); | |
Serial.println(""); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
matrix.begin(0x70); // pass in the ad | |
//for (uint8_t i=0; i<8; i++) { | |
// draw a diagonal row of pixels | |
// matrix.displaybuffer[i] = _BV((counter+i) % 16) | _BV((counter+i+8) % 16) ; | |
//} | |
matrix.print(12.00); | |
matrix.setBrightness(1); | |
matrix.writeDisplay(); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected."); | |
Serial.println("IP address: "); | |
Serial.println(WiFi.localIP()); | |
timeClient.begin(); | |
} | |
void loop() | |
{ | |
timeClient.update(); | |
String formattedTime = timeClient.getFormattedTime(); | |
int minutes = timeClient.getMinutes(); | |
int hours = timeClient.getHours(); | |
matrix.writeDigitNum(4, minutes % 10); | |
matrix.writeDigitNum(3, minutes / 10); | |
matrix.drawColon(dots); | |
matrix.writeDigitNum(1, hours % 10); | |
matrix.writeDigitNum(0, hours / 10); | |
matrix.writeDisplay(); | |
Serial.println(formattedTime[0] + formattedTime[1] + ':' + formattedTime[2] + formattedTime[3]); | |
Serial.println(formattedTime); | |
delay(1000); | |
dots = !dots; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment