Programme d'une sonde de température DHT 11 associée à de la sauvegarde de données sur clé USB et à l'affichage de ces données sur afficheur LCD
Dependencies: FatFileSystemCpp mbed
main.cpp
00001 #include "mbed.h" 00002 #include "MSCFileSystem.h" 00003 #include "DHT.h" 00004 #include "TextLCD.h" 00005 Ticker timer_5s; 00006 MSCFileSystem msc("usb"); // Mount flash drive under the name "msc" 00007 Serial pc(USBTX,USBRX); 00008 DigitalOut led(LED1); 00009 DigitalOut rw(p13); 00010 DHT sensor(p10, DHT11); 00011 TextLCD lcd(p12, p14, p15, p16, p17, p18, TextLCD::LCD16x2); 00012 00013 00014 void attime() 00015 { 00016 led = !led; 00017 } 00018 00019 int main() 00020 00021 { 00022 rw=0; 00023 led =0; 00024 unsigned char data[120*160]; // Test array of data 00025 timer_5s.attach(&attime, 10); 00026 int error = 0; 00027 //float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; 00028 float h = 0.0f, c = 0.0f; 00029 00030 while(1) { 00031 wait(2.0f); 00032 error = sensor.readData(); 00033 if (0 == error) { 00034 c = sensor.ReadTemperature(CELCIUS); 00035 h = sensor.ReadHumidity(); 00036 lcd.locate(0,0); 00037 lcd.printf("Temp : %4.2f\n", c); 00038 lcd.locate(0,1); 00039 lcd.printf("Humid : %4.2f\n", h); 00040 // lcd.printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); 00041 } else { 00042 lcd.printf("Error: %d\n", error); 00043 } 00044 if (led==1) { 00045 wait(0.2); 00046 // Fill the data with values 00047 for (int i=0; i<120*160; i++) { 00048 data[i] = 0xAA; // Fill array with data 00049 } 00050 00051 // Create timers 00052 // Timer Write_time, Read_time; 00053 // Write_time.start(); 00054 00055 // Write to local file 00056 FILE *fp = fopen( "/usb/Mesures.txt", "a"); 00057 00058 for (int i=0; i<1; i++) { 00059 //fprintf(fp, "%c",data[i]); 00060 00061 fprintf(fp, "Temp : %4.2f\n - ",c,data[0]); 00062 fprintf(fp, "Humid : %4.2f\n\r\n", h,data[0]); 00063 } 00064 00065 fclose(fp); 00066 led=0; 00067 } 00068 00069 } 00070 // Write_time.stop(); 00071 // pc.printf("\n\rTime taken so write array = %f seconds",Write_time.read()); 00072 00073 00074 }
Generated on Wed Jul 20 2022 05:14:59 by 1.7.2