Skip to content

Commit 33b6456

Browse files
committed
Refactor setup function to enhance initialization sequence; adjust LCD brightness, buzzer delay, and add display messages for improved user experience
1 parent 84329e4 commit 33b6456

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

ESP32-GPS-Clock-V2.ino

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,27 @@ void setup(void)
388388
if (getCpuFrequencyMhz() != 160)
389389
setCpuFrequencyMhz(160); // if not 160MHz, set to 160MHz
390390
Serial.begin(115200);
391+
Wire.begin();
391392
Serial1.begin(9600, SERIAL_8N1, RXPin, TXPin); // for GPS running on Hardware Serial
392393
pinMode(LCD_LIGHT, OUTPUT);
393-
analogWrite(LCD_LIGHT, 250);
394+
analogWrite(LCD_LIGHT, 50);
394395

395396
pinMode(BUZZER_PIN, OUTPUT);
396397
digitalWrite(BUZZER_PIN, HIGH);
397-
delay(100);
398+
delay(50);
398399
digitalWrite(BUZZER_PIN, LOW);
399400

401+
analogWrite(LCD_LIGHT, 250);
402+
403+
u8g2.begin();
404+
u8g2.clearBuffer();
405+
u8g2.drawLine(0, 17, 127, 17);
406+
u8g2.setFont(u8g2_font_7x14B_mr);
407+
u8g2.setCursor(12, 30);
408+
u8g2.print("GPS Clock V2");
409+
u8g2.drawLine(0, 31, 127, 31);
410+
u8g2.sendBuffer();
411+
400412
if (!pref.begin("database", false)) // open database
401413
errorMsgPrint("DATABASE", "ERROR INITIALIZE");
402414

@@ -449,24 +461,14 @@ void setup(void)
449461
}
450462
buzzVol = pref.getInt("buzzVol", 50);
451463

452-
analogWrite(LCD_LIGHT, LCD_BRIGHTNESS);
453-
Wire.begin();
454-
455464
if (!lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE))
456465
errorMsgPrint("BH1750", "CANNOT FIND");
457466

458467
if (aht20.begin() != true)
459468
{
460469
errorMsgPrint("AHT25", "CANNOT FIND");
461470
}
462-
u8g2.begin();
463-
u8g2.clearBuffer();
464-
u8g2.setFont(u8g2_font_7x14B_mr);
465-
u8g2.setCursor(12, 15);
466-
u8g2.print("RETRO");
467-
u8g2.setCursor(12, 30);
468-
u8g2.print("GPS CLOCK");
469-
u8g2.sendBuffer();
471+
470472
xTaskCreatePinnedToCore(
471473
loop1, /* Task function. */
472474
"loop1Task", /* name of task. */
@@ -476,7 +478,7 @@ void setup(void)
476478
&loop1Task, /* Task handle to keep track of created task */
477479
0); /* pin task to core 0 */
478480

479-
delay(2500);
481+
delay(1000);
480482

481483
// wifi manager
482484
if (useWifi)
@@ -615,7 +617,7 @@ void setup(void)
615617
u8g2.setFont(u8g2_font_streamline_food_drink_t);
616618
u8g2.drawUTF8(80, 54, "U+4"); // birthday cake icon
617619
u8g2.sendBuffer();
618-
delay(2500);
620+
delay(2000);
619621

620622
pref.end();
621623
ahtTemp = (aht20.readTemperature() - 3); // NEED TO CHANGE THE SENSOR, it shows +3 degrees extra

0 commit comments

Comments
 (0)