Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:b5d2f9051fc7
- Parent:
- 0:0ac1b1ae4b2f
- Child:
- 2:a8d9981c9155
diff -r 0ac1b1ae4b2f -r b5d2f9051fc7 main.cpp --- a/main.cpp Tue Dec 01 13:02:35 2020 +0000 +++ b/main.cpp Tue Dec 01 13:06:09 2020 +0000 @@ -1,96 +1,1 @@ -#include "mbed.h" -#include <cstdio> -// main() runs in its own thread in the OS -#include "ThisThread.h" -#include "mbed.h" -#include "C12832.h" -#include <stdio.h> -#include "LM75B.h" -#include "platform/mbed_thread.h" -// this solution unsure every thread is accessing the file, the LCD and the LM78B at a diffrent time -Thread t2; -Thread t1; -DigitalOut myled(LED1); -LocalFileSystem local("local"); // Create the local filesystem under the name "local" -C12832 lcd(p5, p7, p6, p8, p11); -LM75B sensor(p28, p27); -void thread_function(void const *arg){ - int sleepwait=atoi((char*)arg); - ThisThread::sleep_for(sleepwait*3*1000); - FILE *fp = fopen("/local/logtemp.txt", "w"); - lcd.cls(); - float max=0,min=0,avg=0,current;int count=0; - char buffer[200] ; - fprintf(fp, "Temperature:\n"); - fclose(fp); - while(1) { - - - fp = fopen("/local/logtemp.txt", "a"); - printf("Thread ID%d\n",sleepwait); - if (fp!=NULL){ - - if (sensor.open()) { - printf("Device detected!\n"); - printf("Temp = %.3f\n", sensor.temp()); - fprintf (fp,"%.3f\n",sensor.temp()); - - } else { - error("Device not detected!\n"); - } - fclose (fp); - } - - - fp = fopen("/local/logtemp.txt", "r"); - max=0;min=0;avg=0;count=0; - if(fp) { - while( fgets(buffer,200,fp) ) { - if(count==0){ - printf("reading from file %s\n",buffer); - count++; - continue; - } - // printf("Reading from file %s\n",buffer); - count++; - current=atof(buffer); - if(current>=max) - max=current; - if(current<=min) - min=current; - avg+=current; - } - if(count==0) - count=1; - avg=avg/count; - printf("Minimum Temp = %.3f\n", min); - printf("Maximum Temp = %.3f\n", max); - printf("Average Temp = %.3f\n", avg); - lcd.locate(0,1); - lcd.printf("Minimum Temp = %.3f", min); - lcd.locate(0,10); - lcd.printf("Maximum Temp = %.3f", max); - lcd.locate(0,20); - lcd.printf("Average Temp = %.3f", avg); - fclose(fp); - fclose(fp); - } - - - - ThisThread::sleep_for(10000); - } - -} - -int main() { - t1.start(callback(thread_function,(void*)"2")); - t2.start(callback(thread_function,(void*)"3")); - thread_function((void*)"1"); - // this solution unsure every thread is accessing the file, the LCD and the LM78B at a diffrent time - - -} - -