forked from Winston-Lu/ESP8266-LED-Shelf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED_Clock.ino
114 lines (98 loc) · 2.82 KB
/
LED_Clock.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
#include <Arduino.h> //Delete or comment out if you're going to use Arduino IDE, leave if you want you use platform.io
#include <LittleFS.h>
#include "Config.h"
#include "NTPTime.h"
#include "Lighting.h"
#include "WebServer.h"
#include "Backlight.h"
byte FRAMES_PER_SECOND = 30; //will be overwritten later on by EEPROM or default settings
unsigned long frameStart; //For fps counter
void setup(){
Serial.begin(115200);
pinMode(LIGHT_SENSOR,INPUT);
Serial.println("\n\n\n\n\n"); //get rid of the jiberish from boot
random16_add_entropy((uint16_t)random16());
for(int i=0;i<10;i++) random16_add_entropy(random(65535));
//Wipe EEPROM if specified
#ifdef RESET_EEPROM
resetEEPROM();
#endif
//FastLED Setup
fastLEDInit();
FastLED.setDither(false);
FastLED.setBrightness(255);
FastLED.setMaxPowerInVoltsAndMilliamps(5, MILLI_AMPS);
solidSegments(CRGB::Black);
Serial.println("Initializing data structures for lighting effects");
lightingInit();
#ifdef BACKLIGHT
initBacklight();
#endif
if (!LittleFS.begin()) {
Serial.println("Mounting LittleFS failed");
return;
}
Serial.println("Listing directory: /");
File root = LittleFS.open("/");
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file) {
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
Serial.printf("\n");
//WiFi Setup
Serial.println("Setting up Wi-Fi and NTP Connection");
setupWiFi();
Serial.println("Showing lights");
showLightingEffects();
Serial.println("Getting webserver started...");
setupServer();
}
uint16_t counter = 0;
void loop() {
//Track FPS
if (counter==FRAMES_PER_SECOND*5) frameStart = micros();
//Pretty much the only 2 lines that get called aside from the last 2 FastLED calls
showLightingEffects();
#ifdef BACKLIGHT
showBacklight();
#endif
//Track FPS
if(counter>=FRAMES_PER_SECOND*5){
unsigned long microsecondsPerFrame = micros()-frameStart;
char buff[60];
sprintf(buff, "Maximum FPS: %.1f Milliseconds per frame: %.2f",1000000.0/microsecondsPerFrame,microsecondsPerFrame/1000.0);
Serial.println(buff);
counter = 0;
}
counter++;
//Track EEPROM updates
lastUpdate++;
if(lastUpdate >= EEPROM_UPDATE_DELAY*FRAMES_PER_SECOND && updateSettings){
lastUpdate = 0;
updateSettings = false;
storeEEPROM();
#ifdef BACKLIGHT
saveBLEEPROM();
#endif
}
// insert a delay to maintain framerate.
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
}