-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathc3.ino
134 lines (102 loc) · 2.96 KB
/
c3.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <Adafruit_NeoPixel.h>
#include <ezTime.h>
#include <WiFiManager.h>
#include "font.h"
#define CHAR_WIDTH 5
#define CHAR_HEIGHT 5
#define LED_PIN 8
#define LED_COUNT 25
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t amber = strip.Color(255, 140, 0);
Timezone myTZ;
void DrawPixel(uint32_t colour, uint8_t x, uint8_t y, uint8_t brightness) {
uint8_t led = (4 - y) * 5 + (4 - x); // Calc LED from x,y coords, 0,0 is bottom left pixel
uint8_t red = ((colour >> 16) & 0xff) * brightness / 100;
uint8_t green = ((colour >> 8 ) & 0xff) * brightness / 100;
uint8_t blue = (colour & 0xff) * brightness / 100;
strip.setPixelColor(led, red, green, blue);
//strip.show();
}
// Based on code from https://jared.geek.nz/2014/jan/custom-fonts-for-microcontrollers
void DrawChar(uint32_t colour, char c, uint8_t brightness) {
uint8_t x, y;
// Convert the character to an index
c = c & 0x7F;
if (c < ' ') {
c = 0;
} else {
c -= ' ';
}
// 'font' is a multidimensional array of [96][char_width]
const uint8_t* chr = font[c];
// Draw pixels
for (x = 0; x < CHAR_WIDTH; x++) {
for (y = 0; y < CHAR_HEIGHT; y++) {
if (chr[x] >> 2 & (1 << y)) {
DrawPixel(colour, x, y, brightness);
}
strip.show();
}
}
}
void FadeChar(uint32_t colour, char c) {
for (uint8_t br = 20; br <= 100; br = br + 5) {
DrawChar(colour, c, br);
}
delay(100);
for (uint8_t br = 100; br > 0; br = br - 5) {
DrawChar(colour, c, br);
}
delay(100);
strip.clear();
strip.show(); // Initialize all pixels to 'off'
}
void FadeString(uint32_t colour, String s) {
char buffer[s.length() + 1];
s.toCharArray(buffer, s.length() + 1);
for (int i = 0; i < s.length() + 1; i++)
FadeChar(colour, buffer[i]);
}
void GetNTP() {
WiFi.mode(WIFI_STA);
WiFi.setTxPower(WIFI_POWER_5dBm);
WiFiManager wm;
wm.setDebugOutput(false);
bool res;
res = wm.autoConnect("5x5_Clock", "Clock123"); // create password protected ap
if (!res) {
Serial.println(F("Failed to start Wifi Manager AP"));
} else {
Serial.println(F("[+] Connected to Wi-Fi"));
Serial.println(F("[+] Syncing NTP"));
waitForSync();
Serial.println("[+] UTC: " + UTC.dateTime());
if (myTZ.setLocation(F("Europe/London"))) {
Serial.println(F("[+] Timezone lookup OK"));
Serial.print("[+] UK: ");
Serial.println(myTZ.dateTime());
} else {
Serial.println("[-] Timezone lookup failed, will use UTC");
myTZ = UTC;
}
}
WiFi.disconnect();
}
void setup() {
strip.begin();
strip.setBrightness(20);
strip.show(); // Initialize all pixels to 'off'
FadeString(red, "Wifi");
GetNTP();
FadeString(green, "Up");
}
void loop() {
events();
if (minuteChanged()) {
FadeString(blue, myTZ.dateTime("dmy"));
}
FadeString(amber, myTZ.dateTime("H:i"));
}