فهرست منبع

reordenar un poco el setup

dacowars 2 هفته پیش
والد
کامیت
7e051d34e6
1فایلهای تغییر یافته به همراه34 افزوده شده و 25 حذف شده
  1. 34 25
      V1/V1.ino

+ 34 - 25
V1/V1.ino

@@ -46,6 +46,35 @@ void ARDUINO_ISR_ATTR onTimer(void) {
 
 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
+void DHT_test() {
+  float h = dht.readHumidity();
+  float t = dht.readTemperature();
+  if (isnan(h) || isnan(t)) {
+    Serial.println("Failed to read from DHT sensor!");
+    return;
+  }
+  Serial.print("Humidity: ");
+  Serial.print(h);
+  Serial.print(" %\t");
+  Serial.print("Temperature: ");
+  Serial.print(t);
+  Serial.println(" *C");
+}
+
+void OLED_test() {  //pantallazo a blanco y luego iniciando
+  display.clearDisplay();
+  display.fillScreen(SSD1306_WHITE); // Pantalla blanca
+  display.display();
+  display.clearDisplay();
+  display.setTextSize(2);         // Tamaño texto
+  display.setTextColor(SSD1306_WHITE);
+  display.setCursor(0, 0);        // Posición
+  display.println("¡Hola ESP32!");
+  display.println("OLED OK!");
+  display.display();              // Muestra
+  delay(1000);
+}
+
 void setup() {
   Serial.begin(115200);
 
@@ -88,22 +117,14 @@ void setup() {
     Serial.println("SD Card Mounted");
   }
 
+  OLED_test();
+
+  // DHT check
+  DHT_test();
+
 }
 //revisar toda esta parte, generada por copilot##########################################################
 void loop() {
-  // DHT check
-  float h = dht.readHumidity();
-  float t = dht.readTemperature();
-  if (isnan(h) || isnan(t)) {
-    Serial.println("Failed to read from DHT sensor!");
-  } else {
-    Serial.print("Humidity: ");
-    Serial.print(h);
-    Serial.print(" %\t");
-    Serial.print("Temperature: ");
-    Serial.print(t);
-    Serial.println(" *C");
-  }
 
   // GPS check
   if (gpsFlag) {
@@ -152,16 +173,4 @@ void loop() {
     }
   }
 
-  // Update OLED
-  display.clearDisplay();
-  display.setCursor(0, 0);
-  display.setTextSize(1); // Smaller text for more info
-  display.printf("Temp: %.1f C\nHum: %.1f %%\n", t, h);
-  if (gps.location.isValid()) {
-    display.printf("Lat: %.4f\nLon: %.4f", gps.location.lat(), gps.location.lng());
-  } else {
-    display.println("GPS: No fix");
-  }
-  display.display();
-  delay(1000);
 }