├── .gitattributes ├── BTTF_LAMP_CLOCK_HARD_CODED_CREDENTIAL.ino ├── BTTF_LAMP_CLOCK_WEBPORTAL.ino ├── BTTF_LAMP_CLOCK_HARD_CODED_CREDENTIAL_12H.ino └── BTTF_LAMP_CLOCK_WEBPORTAL_12H.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /BTTF_LAMP_CLOCK_HARD_CODED_CREDENTIAL.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "Adafruit_NeoPixel.h" 3 | #include "TM1637Display.h" 4 | #include "WiFiManager.h" 5 | #include "NTPClient.h" 6 | 7 | 8 | // Which pin on the Arduino is connected to the NeoPixels? 9 | #define PIN 5 // Strip led DIN 10 | 11 | #define red_CLK 16 12 | #define red1_DIO 17 13 | #define red2_DIO 18 14 | #define red3_DIO 19 15 | 16 | #define AM 32 17 | #define PM 33 18 | 19 | // How many NeoPixels are attached to the Arduino? 20 | #define NUMPIXELS 48 // Popular NeoPixel ring size 21 | 22 | bool res; 23 | int var=0; 24 | int analogPin = 34; 25 | const long utcOffsetInSeconds = 3600; // Offset in second 26 | 27 | //========================USEFUL VARIABLES============================= 28 | int UTC = 2; // UTC + value in hour - Summer time 29 | int Display_backlight = 3; // Set displays brightness 0 to 7; 30 | 31 | const char *ssid = "YOUR SSID HERE"; 32 | const char *password = "WIFI PASSWORD HERE"; 33 | 34 | //====================================================================== 35 | 36 | 37 | // When setting up the NeoPixel library, we tell it how many pixels, 38 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 39 | // Setup the red displays 40 | TM1637Display red1(red_CLK, red1_DIO); 41 | TM1637Display red2(red_CLK, red2_DIO); 42 | TM1637Display red3(red_CLK, red3_DIO); 43 | 44 | WiFiUDP ntpUDP; 45 | NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds*UTC); 46 | 47 | void setup() { 48 | 49 | pinMode(PIN, OUTPUT); 50 | pinMode(red_CLK, OUTPUT); 51 | pinMode(red1_DIO, OUTPUT); 52 | pinMode(red2_DIO, OUTPUT); 53 | pinMode(red3_DIO, OUTPUT); 54 | pinMode(AM, OUTPUT); 55 | pinMode(PM, OUTPUT); 56 | 57 | pinMode(analogPin, INPUT); 58 | //manager.resetSettings(); 59 | 60 | Serial.begin(9600); 61 | 62 | WiFi.begin(ssid, password); 63 | 64 | while ( WiFi.status() != WL_CONNECTED ) { 65 | delay ( 500 ); 66 | Serial.print ( "." ); 67 | } 68 | 69 | timeClient.begin(); 70 | 71 | red1.setBrightness(Display_backlight); 72 | red2.setBrightness(Display_backlight); 73 | red3.setBrightness(Display_backlight); 74 | pixels.setBrightness(250); 75 | 76 | } 77 | 78 | void loop() { 79 | 80 | timeClient.update(); 81 | Serial.print("Time: "); 82 | Serial.println(timeClient.getFormattedTime()); 83 | unsigned long epochTime = timeClient.getEpochTime(); 84 | struct tm *ptm = gmtime ((time_t *)&epochTime); 85 | int currentYear = ptm->tm_year+1900; 86 | Serial.print("Year: "); 87 | Serial.println(currentYear); 88 | 89 | int monthDay = ptm->tm_mday; 90 | Serial.print("Month day: "); 91 | Serial.println(monthDay); 92 | 93 | int currentMonth = ptm->tm_mon+1; 94 | Serial.print("Month: "); 95 | Serial.println(currentMonth); 96 | 97 | red1.showNumberDecEx(currentMonth,0b01000000,true,2,0); 98 | red1.showNumberDecEx(monthDay,0b01000000,true,2,2); 99 | red2.showNumberDecEx(currentYear,0b00000000,true); 100 | red3.showNumberDecEx(timeClient.getHours(),0b01000000,true,2,0); 101 | red3.showNumberDecEx(timeClient.getMinutes(),0b01000000,true,2,2); 102 | 103 | if((currentMonth*30 + monthDay) >= 121 && (currentMonth*30 + monthDay) < 331){ 104 | timeClient.setTimeOffset(utcOffsetInSeconds*UTC);} // Change daylight saving time - Summer 105 | else {timeClient.setTimeOffset((utcOffsetInSeconds*UTC) - 3600);} // Change daylight saving time - Winter 106 | 107 | 108 | if(timeClient.getHours()>=13){ 109 | digitalWrite(AM,0); 110 | digitalWrite(PM,1);} 111 | 112 | else if(timeClient.getHours()==12){ 113 | digitalWrite(AM,0); 114 | digitalWrite(PM,1);} 115 | 116 | else{ 117 | digitalWrite(AM,1); 118 | digitalWrite(PM,0);} 119 | 120 | 121 | pixels.clear(); // Set all pixel colors to 'off' 122 | 123 | if(var>3){var = 0;} // Reset counter 124 | 125 | // read the switch 126 | if(analogRead(analogPin) > 100) 127 | { 128 | var = var+1 ; 129 | delay(45); 130 | } 131 | 132 | Serial.print("Var="); 133 | Serial.println(var); 134 | Serial.print("Digital="); 135 | Serial.println(analogRead(analogPin)); 136 | 137 | delay(100); 138 | switch (var) { 139 | case 0: 140 | for(int i=0; i<6;i++){ 141 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 142 | } 143 | for(int i=6; i<12;i++){ 144 | pixels.setPixelColor(i, pixels.Color(160,160,0)); 145 | } 146 | for(int i=12; i<18;i++){ 147 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 148 | } 149 | pixels.show(); 150 | break; 151 | 152 | case 1: 153 | for(int i=0; i<6;i++){ 154 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 155 | } 156 | for(int i=6; i<12;i++){ 157 | pixels.setPixelColor(i, pixels.Color(200,250,255)); 158 | 159 | } 160 | for(int i=12; i<18;i++){ 161 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 162 | } 163 | pixels.show(); 164 | break; 165 | 166 | case 2: 167 | pixels.clear(); 168 | for(int i=0; i<6;i++){ 169 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 170 | } 171 | for(int i=6; i<12;i++){ 172 | pixels.setPixelColor(i, pixels.Color(0,10,255)); 173 | } 174 | for(int i=12; i<18;i++){ 175 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 176 | } 177 | pixels.show(); 178 | break; 179 | 180 | case 3: 181 | pixels.clear(); 182 | for(int i=0; i<16;i++){ 183 | pixels.setPixelColor(i, pixels.Color(0,0,0)); 184 | } 185 | pixels.show(); 186 | break; 187 | 188 | } 189 | 190 | 191 | 192 | } 193 | 194 | -------------------------------------------------------------------------------- /BTTF_LAMP_CLOCK_WEBPORTAL.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "Adafruit_NeoPixel.h" 3 | #include "TM1637Display.h" 4 | #include "WiFiManager.h" 5 | #include "NTPClient.h" 6 | 7 | 8 | // Which pin on the Arduino is connected to the NeoPixels? 9 | #define PIN 5 // Strip led DIN 10 | 11 | #define red_CLK 16 12 | #define red1_DIO 17 13 | #define red2_DIO 18 14 | #define red3_DIO 19 15 | 16 | #define AM 32 17 | #define PM 33 18 | 19 | // How many NeoPixels are attached to the Arduino? 20 | #define NUMPIXELS 48 // Popular NeoPixel ring size 21 | 22 | bool res; 23 | int var=0; 24 | int analogPin = 34; 25 | const long utcOffsetInSeconds = 3600; // Offset in second 26 | 27 | //========================USEFUL VARIABLES============================= 28 | int UTC = 2; // UTC + value in hour - Summer time 29 | int Display_backlight = 3; // Set displays brightness 0 to 7; 30 | //====================================================================== 31 | 32 | // When setting up the NeoPixel library, we tell it how many pixels, 33 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 34 | // Setup the red displays 35 | TM1637Display red1(red_CLK, red1_DIO); 36 | TM1637Display red2(red_CLK, red2_DIO); 37 | TM1637Display red3(red_CLK, red3_DIO); 38 | 39 | WiFiUDP ntpUDP; 40 | NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds*UTC); 41 | 42 | void setup() { 43 | 44 | pinMode(PIN, OUTPUT); 45 | pinMode(red_CLK, OUTPUT); 46 | pinMode(red1_DIO, OUTPUT); 47 | pinMode(red2_DIO, OUTPUT); 48 | pinMode(red3_DIO, OUTPUT); 49 | pinMode(AM, OUTPUT); 50 | pinMode(PM, OUTPUT); 51 | 52 | pinMode(analogPin, INPUT); 53 | //manager.resetSettings(); 54 | 55 | Serial.begin(9600); 56 | 57 | WiFiManager manager; 58 | 59 | manager.setTimeout(180); 60 | //fetches ssid and password and tries to connect, if connections succeeds it starts an access point with the name called "BTTF_CLOCK" and waits in a blocking loop for configuration 61 | res = manager.autoConnect("BTTF_LAMP_CLOCK","password"); 62 | 63 | if(!res) { 64 | Serial.println("failed to connect and timeout occurred"); 65 | ESP.restart(); //reset and try again 66 | } 67 | 68 | delay(3000); 69 | 70 | timeClient.begin(); 71 | red1.setBrightness(Display_backlight); 72 | red2.setBrightness(Display_backlight); 73 | red3.setBrightness(Display_backlight); 74 | pixels.setBrightness(250); 75 | 76 | } 77 | 78 | void loop() { 79 | 80 | timeClient.update(); 81 | Serial.print("Time: "); 82 | Serial.println(timeClient.getFormattedTime()); 83 | unsigned long epochTime = timeClient.getEpochTime(); 84 | struct tm *ptm = gmtime ((time_t *)&epochTime); 85 | int currentYear = ptm->tm_year+1900; 86 | Serial.print("Year: "); 87 | Serial.println(currentYear); 88 | 89 | int monthDay = ptm->tm_mday; 90 | Serial.print("Month day: "); 91 | Serial.println(monthDay); 92 | 93 | int currentMonth = ptm->tm_mon+1; 94 | Serial.print("Month: "); 95 | Serial.println(currentMonth); 96 | 97 | red1.showNumberDecEx(currentMonth,0b01000000,true,2,0); 98 | red1.showNumberDecEx(monthDay,0b01000000,true,2,2); 99 | red2.showNumberDecEx(currentYear,0b00000000,true); 100 | red3.showNumberDecEx(timeClient.getHours(),0b01000000,true,2,0); 101 | red3.showNumberDecEx(timeClient.getMinutes(),0b01000000,true,2,2); 102 | 103 | if((currentMonth*30 + monthDay) >= 121 && (currentMonth*30 + monthDay) < 331){ 104 | timeClient.setTimeOffset(utcOffsetInSeconds*UTC);} // Change daylight saving time - Summer 105 | else {timeClient.setTimeOffset((utcOffsetInSeconds*UTC) - 3600);} // Change daylight saving time - Winter 106 | 107 | 108 | if(timeClient.getHours()>=13){ 109 | digitalWrite(AM,0); 110 | digitalWrite(PM,1);} 111 | 112 | else if(timeClient.getHours()==12){ 113 | digitalWrite(AM,0); 114 | digitalWrite(PM,1);} 115 | 116 | else{ 117 | digitalWrite(AM,1); 118 | digitalWrite(PM,0);} 119 | 120 | 121 | pixels.clear(); // Set all pixel colors to 'off' 122 | 123 | if(var>3){var = 0;} // Reset counter 124 | 125 | // read the switch 126 | if(analogRead(analogPin) > 100) 127 | { 128 | var = var+1 ; 129 | delay(45); 130 | } 131 | 132 | Serial.print("Var="); 133 | Serial.println(var); 134 | Serial.print("Digital="); 135 | Serial.println(analogRead(analogPin)); 136 | 137 | delay(100); 138 | switch (var) { 139 | case 0: 140 | for(int i=0; i<6;i++){ 141 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 142 | } 143 | for(int i=6; i<12;i++){ 144 | pixels.setPixelColor(i, pixels.Color(160,160,0)); 145 | } 146 | for(int i=12; i<18;i++){ 147 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 148 | } 149 | pixels.show(); 150 | break; 151 | 152 | case 1: 153 | for(int i=0; i<6;i++){ 154 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 155 | } 156 | for(int i=6; i<12;i++){ 157 | pixels.setPixelColor(i, pixels.Color(200,250,255)); 158 | 159 | } 160 | for(int i=12; i<18;i++){ 161 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 162 | } 163 | pixels.show(); 164 | break; 165 | 166 | case 2: 167 | pixels.clear(); 168 | for(int i=0; i<6;i++){ 169 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 170 | } 171 | for(int i=6; i<12;i++){ 172 | pixels.setPixelColor(i, pixels.Color(0,10,255)); 173 | } 174 | for(int i=12; i<18;i++){ 175 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 176 | } 177 | pixels.show(); 178 | break; 179 | 180 | case 3: 181 | pixels.clear(); 182 | for(int i=0; i<16;i++){ 183 | pixels.setPixelColor(i, pixels.Color(0,0,0)); 184 | } 185 | pixels.show(); 186 | break; 187 | 188 | } 189 | 190 | 191 | 192 | } 193 | 194 | -------------------------------------------------------------------------------- /BTTF_LAMP_CLOCK_HARD_CODED_CREDENTIAL_12H.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "Adafruit_NeoPixel.h" 3 | #include "TM1637Display.h" 4 | #include "WiFiManager.h" 5 | #include "NTPClient.h" 6 | 7 | 8 | // Which pin on the Arduino is connected to the NeoPixels? 9 | #define PIN 5 // Strip led DIN 10 | 11 | #define red_CLK 16 12 | #define red1_DIO 17 13 | #define red2_DIO 18 14 | #define red3_DIO 19 15 | 16 | #define AM 32 17 | #define PM 33 18 | 19 | // How many NeoPixels are attached to the Arduino? 20 | #define NUMPIXELS 48 // Popular NeoPixel ring size 21 | 22 | bool res; 23 | int var=0; 24 | int analogPin = 34; 25 | const long utcOffsetInSeconds = 3600; // Offset in second 26 | int Hour = 0; 27 | 28 | //========================USEFUL VARIABLES============================= 29 | int UTC = 2; // UTC + value in hour - Summer time 30 | int Display_backlight = 3; // Set displays brightness 0 to 7; 31 | 32 | const char *ssid = "YOUR SSID HERE"; 33 | const char *password = "WIFI PASSWORD HERE"; 34 | 35 | //====================================================================== 36 | 37 | 38 | // When setting up the NeoPixel library, we tell it how many pixels, 39 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 40 | // Setup the red displays 41 | TM1637Display red1(red_CLK, red1_DIO); 42 | TM1637Display red2(red_CLK, red2_DIO); 43 | TM1637Display red3(red_CLK, red3_DIO); 44 | 45 | WiFiUDP ntpUDP; 46 | NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds*UTC); 47 | 48 | void setup() { 49 | 50 | pinMode(PIN, OUTPUT); 51 | pinMode(red_CLK, OUTPUT); 52 | pinMode(red1_DIO, OUTPUT); 53 | pinMode(red2_DIO, OUTPUT); 54 | pinMode(red3_DIO, OUTPUT); 55 | pinMode(AM, OUTPUT); 56 | pinMode(PM, OUTPUT); 57 | 58 | pinMode(analogPin, INPUT); 59 | //manager.resetSettings(); 60 | 61 | Serial.begin(9600); 62 | 63 | WiFi.begin(ssid, password); 64 | 65 | while ( WiFi.status() != WL_CONNECTED ) { 66 | delay ( 500 ); 67 | Serial.print ( "." ); 68 | } 69 | 70 | timeClient.begin(); 71 | 72 | red1.setBrightness(Display_backlight); 73 | red2.setBrightness(Display_backlight); 74 | red3.setBrightness(Display_backlight); 75 | pixels.setBrightness(250); 76 | 77 | } 78 | 79 | void loop() { 80 | 81 | timeClient.update(); 82 | Serial.print("Time: "); 83 | Serial.println(timeClient.getFormattedTime()); 84 | unsigned long epochTime = timeClient.getEpochTime(); 85 | struct tm *ptm = gmtime ((time_t *)&epochTime); 86 | int currentYear = ptm->tm_year+1900; 87 | Serial.print("Year: "); 88 | Serial.println(currentYear); 89 | 90 | int monthDay = ptm->tm_mday; 91 | Serial.print("Month day: "); 92 | Serial.println(monthDay); 93 | 94 | int currentMonth = ptm->tm_mon+1; 95 | Serial.print("Month: "); 96 | Serial.println(currentMonth); 97 | if (timeClient.getHours() == 0) 98 | { 99 | Hour = 12; 100 | Serial.write(" =0"); 101 | } 102 | 103 | else if (timeClient.getHours() == 12) 104 | { 105 | Hour = timeClient.getHours(); 106 | Serial.write(" =12"); 107 | } 108 | 109 | else if (timeClient.getHours() >= 13) { 110 | Hour = timeClient.getHours() - 12; 111 | Serial.write(" >=13"); 112 | } 113 | 114 | else { 115 | Hour = timeClient.getHours(); 116 | } 117 | 118 | red1.showNumberDecEx(currentMonth,0b01000000,true,2,0); 119 | red1.showNumberDecEx(monthDay,0b01000000,true,2,2); 120 | red2.showNumberDecEx(currentYear,0b00000000,true); 121 | red3.showNumberDecEx(Hour,0b01000000,true,2,0); 122 | red3.showNumberDecEx(timeClient.getMinutes(),0b01000000,true,2,2); 123 | 124 | if((currentMonth*30 + monthDay) >= 121 && (currentMonth*30 + monthDay) < 331){ 125 | timeClient.setTimeOffset(utcOffsetInSeconds*UTC);} // Change daylight saving time - Summer 126 | else {timeClient.setTimeOffset((utcOffsetInSeconds*UTC) - 3600);} // Change daylight saving time - Winter 127 | 128 | 129 | if(timeClient.getHours()>=13){ 130 | digitalWrite(AM,0); 131 | digitalWrite(PM,1);} 132 | 133 | else if(timeClient.getHours()==12){ 134 | digitalWrite(AM,0); 135 | digitalWrite(PM,1);} 136 | 137 | else{ 138 | digitalWrite(AM,1); 139 | digitalWrite(PM,0);} 140 | 141 | 142 | pixels.clear(); // Set all pixel colors to 'off' 143 | 144 | if(var>3){var = 0;} // Reset counter 145 | 146 | // read the switch 147 | if(analogRead(analogPin) > 100) 148 | { 149 | var = var+1 ; 150 | delay(45); 151 | } 152 | 153 | Serial.print("Var="); 154 | Serial.println(var); 155 | Serial.print("Digital="); 156 | Serial.println(analogRead(analogPin)); 157 | 158 | delay(100); 159 | switch (var) { 160 | case 0: 161 | for(int i=0; i<6;i++){ 162 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 163 | } 164 | for(int i=6; i<12;i++){ 165 | pixels.setPixelColor(i, pixels.Color(160,160,0)); 166 | } 167 | for(int i=12; i<18;i++){ 168 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 169 | } 170 | pixels.show(); 171 | break; 172 | 173 | case 1: 174 | for(int i=0; i<6;i++){ 175 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 176 | } 177 | for(int i=6; i<12;i++){ 178 | pixels.setPixelColor(i, pixels.Color(200,250,255)); 179 | 180 | } 181 | for(int i=12; i<18;i++){ 182 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 183 | } 184 | pixels.show(); 185 | break; 186 | 187 | case 2: 188 | pixels.clear(); 189 | for(int i=0; i<6;i++){ 190 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 191 | } 192 | for(int i=6; i<12;i++){ 193 | pixels.setPixelColor(i, pixels.Color(0,10,255)); 194 | } 195 | for(int i=12; i<18;i++){ 196 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 197 | } 198 | pixels.show(); 199 | break; 200 | 201 | case 3: 202 | pixels.clear(); 203 | for(int i=0; i<16;i++){ 204 | pixels.setPixelColor(i, pixels.Color(0,0,0)); 205 | } 206 | pixels.show(); 207 | break; 208 | 209 | } 210 | 211 | 212 | 213 | } 214 | 215 | -------------------------------------------------------------------------------- /BTTF_LAMP_CLOCK_WEBPORTAL_12H.ino: -------------------------------------------------------------------------------- 1 | 2 | #include "Adafruit_NeoPixel.h" 3 | #include "TM1637Display.h" 4 | #include "WiFiManager.h" 5 | #include "NTPClient.h" 6 | 7 | 8 | // Which pin on the Arduino is connected to the NeoPixels? 9 | #define PIN 5 // Strip led DIN 10 | 11 | #define red_CLK 16 12 | #define red1_DIO 17 13 | #define red2_DIO 18 14 | #define red3_DIO 19 15 | 16 | #define AM 32 17 | #define PM 33 18 | 19 | // How many NeoPixels are attached to the Arduino? 20 | #define NUMPIXELS 48 // Popular NeoPixel ring size 21 | 22 | bool res; 23 | int var=0; 24 | int analogPin = 34; 25 | const long utcOffsetInSeconds = 3600; // Offset in second 26 | int Hour = 0; 27 | 28 | //========================USEFUL VARIABLES============================= 29 | int UTC = 2; // UTC + value in hour - Summer time 30 | int Display_backlight = 3; // Set displays brightness 0 to 7; 31 | //====================================================================== 32 | 33 | // When setting up the NeoPixel library, we tell it how many pixels, 34 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 35 | // Setup the red displays 36 | TM1637Display red1(red_CLK, red1_DIO); 37 | TM1637Display red2(red_CLK, red2_DIO); 38 | TM1637Display red3(red_CLK, red3_DIO); 39 | 40 | WiFiUDP ntpUDP; 41 | NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds*UTC); 42 | 43 | void setup() { 44 | 45 | pinMode(PIN, OUTPUT); 46 | pinMode(red_CLK, OUTPUT); 47 | pinMode(red1_DIO, OUTPUT); 48 | pinMode(red2_DIO, OUTPUT); 49 | pinMode(red3_DIO, OUTPUT); 50 | pinMode(AM, OUTPUT); 51 | pinMode(PM, OUTPUT); 52 | 53 | pinMode(analogPin, INPUT); 54 | //manager.resetSettings(); 55 | 56 | Serial.begin(9600); 57 | 58 | WiFiManager manager; 59 | 60 | manager.setTimeout(180); 61 | //fetches ssid and password and tries to connect, if connections succeeds it starts an access point with the name called "BTTF_CLOCK" and waits in a blocking loop for configuration 62 | res = manager.autoConnect("BTTF_LAMP_CLOCK","password"); 63 | 64 | if(!res) { 65 | Serial.println("failed to connect and timeout occurred"); 66 | ESP.restart(); //reset and try again 67 | } 68 | 69 | delay(3000); 70 | 71 | timeClient.begin(); 72 | red1.setBrightness(Display_backlight); 73 | red2.setBrightness(Display_backlight); 74 | red3.setBrightness(Display_backlight); 75 | pixels.setBrightness(250); 76 | 77 | } 78 | 79 | void loop() { 80 | 81 | timeClient.update(); 82 | Serial.print("Time: "); 83 | Serial.println(timeClient.getFormattedTime()); 84 | unsigned long epochTime = timeClient.getEpochTime(); 85 | struct tm *ptm = gmtime ((time_t *)&epochTime); 86 | int currentYear = ptm->tm_year+1900; 87 | Serial.print("Year: "); 88 | Serial.println(currentYear); 89 | 90 | int monthDay = ptm->tm_mday; 91 | Serial.print("Month day: "); 92 | Serial.println(monthDay); 93 | 94 | int currentMonth = ptm->tm_mon+1; 95 | Serial.print("Month: "); 96 | Serial.println(currentMonth); 97 | 98 | if (timeClient.getHours() == 0) 99 | { 100 | Hour = 12; 101 | Serial.write(" =0"); 102 | } 103 | 104 | else if (timeClient.getHours() == 12) 105 | { 106 | Hour = timeClient.getHours(); 107 | Serial.write(" =12"); 108 | } 109 | 110 | else if (timeClient.getHours() >= 13) { 111 | Hour = timeClient.getHours() - 12; 112 | Serial.write(" >=13"); 113 | } 114 | 115 | else { 116 | Hour = timeClient.getHours(); 117 | } 118 | 119 | red1.showNumberDecEx(currentMonth,0b01000000,true,2,0); 120 | red1.showNumberDecEx(monthDay,0b01000000,true,2,2); 121 | red2.showNumberDecEx(currentYear,0b00000000,true); 122 | red3.showNumberDecEx(Hour,0b01000000,true,2,0); 123 | red3.showNumberDecEx(timeClient.getMinutes(),0b01000000,true,2,2); 124 | 125 | if((currentMonth*30 + monthDay) >= 121 && (currentMonth*30 + monthDay) < 331){ 126 | timeClient.setTimeOffset(utcOffsetInSeconds*UTC);} // Change daylight saving time - Summer 127 | else {timeClient.setTimeOffset((utcOffsetInSeconds*UTC) - 3600);} // Change daylight saving time - Winter 128 | 129 | 130 | if(timeClient.getHours()>=13){ 131 | digitalWrite(AM,0); 132 | digitalWrite(PM,1);} 133 | 134 | else if(timeClient.getHours()==12){ 135 | digitalWrite(AM,0); 136 | digitalWrite(PM,1);} 137 | 138 | else{ 139 | digitalWrite(AM,1); 140 | digitalWrite(PM,0);} 141 | 142 | 143 | pixels.clear(); // Set all pixel colors to 'off' 144 | 145 | if(var>3){var = 0;} // Reset counter 146 | 147 | // read the switch 148 | if(analogRead(analogPin) > 100) 149 | { 150 | var = var+1 ; 151 | delay(45); 152 | } 153 | 154 | Serial.print("Var="); 155 | Serial.println(var); 156 | Serial.print("Digital="); 157 | Serial.println(analogRead(analogPin)); 158 | 159 | delay(100); 160 | switch (var) { 161 | case 0: 162 | for(int i=0; i<6;i++){ 163 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 164 | } 165 | for(int i=6; i<12;i++){ 166 | pixels.setPixelColor(i, pixels.Color(160,160,0)); 167 | } 168 | for(int i=12; i<18;i++){ 169 | pixels.setPixelColor(i, pixels.Color(255,0,0)); 170 | } 171 | pixels.show(); 172 | break; 173 | 174 | case 1: 175 | for(int i=0; i<6;i++){ 176 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 177 | } 178 | for(int i=6; i<12;i++){ 179 | pixels.setPixelColor(i, pixels.Color(200,250,255)); 180 | 181 | } 182 | for(int i=12; i<18;i++){ 183 | pixels.setPixelColor(i, pixels.Color(0,0,255)); 184 | } 185 | pixels.show(); 186 | break; 187 | 188 | case 2: 189 | pixels.clear(); 190 | for(int i=0; i<6;i++){ 191 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 192 | } 193 | for(int i=6; i<12;i++){ 194 | pixels.setPixelColor(i, pixels.Color(0,10,255)); 195 | } 196 | for(int i=12; i<18;i++){ 197 | pixels.setPixelColor(i, pixels.Color(255,0,10)); 198 | } 199 | pixels.show(); 200 | break; 201 | 202 | case 3: 203 | pixels.clear(); 204 | for(int i=0; i<16;i++){ 205 | pixels.setPixelColor(i, pixels.Color(0,0,0)); 206 | } 207 | pixels.show(); 208 | break; 209 | 210 | } 211 | 212 | 213 | 214 | } 215 | 216 | --------------------------------------------------------------------------------