BoskoopBase/embadet/main/apple.c

46 lines
1.1 KiB
C
Raw Normal View History

2024-10-11 18:01:48 +02:00
#include "esp_log.h"
2024-10-11 14:21:57 +02:00
#include <stdio.h>
#include <time.h>
#include <onewire.h>
#include <ds18b20.h> // Die Header-Datei mit DS18B20-Funktionen
2024-10-11 18:01:48 +02:00
#include <task.h>
2024-10-11 14:21:57 +02:00
2024-10-11 18:01:48 +02:00
int app_main() {
// Create variable for handler
ds18b20_handler_t sensor;
2024-10-11 14:21:57 +02:00
2024-10-11 18:01:48 +02:00
// Check for any initialization failures
if (!ds18b20_init(&sensor, GPIO_NUM_2, TEMP_RES_12_BIT))
{
ESP_LOGE("TAG", "Failed to initalize DS18B20!");
return 0; // Exit
}
float temp = 0;
// If you doesn't convert temperature you may read 85.0 Celsius,
// as it is default temperature set by DS18B20 if convert command wasn't issued.
// Read temperature
printf("hit");
for(int i = 0; i < 30; ++i) {
// Initalize conversion
ds18b20_convert_temp(&sensor);
temp = ds18b20_read_temp(&sensor);
vTaskDelay(5000 / portTICK_PERIOD_MS);
printf("\n");
printf( "Temperature = %.4f", temp);
};
// Print temperature with 4 decimal places
// (12 bit resolution measurement accuracy is 0.0625 Celsius)
ESP_LOGI("TAG", "Temperature = %.4f", temp);
2024-10-11 14:21:57 +02:00
return 0;
}