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.
Dependencies: BMP280
main.cpp
00001 #include "mbed.h" 00002 #include "WebUI.h" 00003 #include "Serial.h" 00004 #include "Sampling.h" 00005 #include "LCD.h" 00006 #include "SDCard.h" 00007 #include "SDBlockDevice.h" 00008 #include "Logging.h" 00009 00010 //Hardware setup 00011 BMP280 sensor(D14, D15); //Enviromental sensor 00012 AnalogIn LDRSensor(A0); //LDR sensor 00013 DigitalOut SamplingLED(PB_10); //LED to indicate sampling 00014 00015 //SD Card devices 00016 InterruptIn SD_WP(PE_10); 00017 InterruptIn UserButton(USER_BUTTON); 00018 SDBlockDevice sd(PB_5, D12, D13, D10); 00019 DigitalOut GreenLED(PB_11); 00020 00021 //Serial interface 00022 Serial PC(USBTX, USBRX); 00023 00024 //LCD card object. LCD pins and two timeset buttons 00025 ENVDISPLAY lcd(D9, D8, D7, D6, D4, D2,PE_12, PE_14); 00026 00027 //Forward Declaration of Self Test 00028 void POST(void); 00029 00030 int main() 00031 { 00032 //Initialise devices 00033 firstSample = true; //Set only at start of program 00034 logging = false; 00035 00036 //Hardware Self Test 00037 POST(); 00038 00039 //Initialise interrupts and times 00040 SerialStart(); //Start serial comms 00041 lcd.Start(); //Start LCD functionality 00042 SDCardInit(); //Start SDCard functionality 00043 WebUISetup(); //Start Web Interface 00044 ConfigThreadsAndIR(); //Start sampling 00045 00046 00047 //Run 00048 while (true) { 00049 if (NewEnvSample && NewLDRSample) { 00050 //New samples have been captured and are in the register 00051 IncrementIndex(); //Index for buffers 00052 NewEnvSample = false; //Reset sampling threads 00053 NewLDRSample = false; 00054 00055 //Push latest samples to LCD. 00056 lcd.UpdateData(tempReadings[currentIndex],presReadings[currentIndex],LDRReadings[currentIndex],timeReadings[currentIndex]); 00057 LogEvent(Log_IndexInc); //Log position 00058 } 00059 if (logging) { 00060 //Grab from mailbox and print to serial 00061 string QueueData = CheckLoggingQueue(); //Get the data from queue 00062 char char_array[QueueData.length()+1]; //Char array for message 00063 strcpy(char_array, QueueData.c_str()); //String must be converted to char array for printf 00064 PC.printf("%s\n\r",char_array); 00065 } 00066 } 00067 } 00068 00069 void POST(void) 00070 { 00071 printf("------Self Test------\n\r"); 00072 lcd.POST(); 00073 printf("LCD Test Done\n\r"); 00074 printf("SDCard ejected?: %d\n\r",SD_WP.read()); 00075 printf("SDCard Dismount Button: %d\n\r",UserButton.read()); 00076 printf("Flashing SDCard Status LEDs\n\r"); 00077 int i; 00078 for (i=0;i<5;i++){ //Flash the LEDs 00079 GreenLED = 1; 00080 SDCardStatusLED = 0; 00081 Thread::wait(200); 00082 GreenLED = 0; 00083 SDCardStatusLED = 1; 00084 Thread::wait(200); 00085 } 00086 SDCardStatusLED = 0; 00087 printf("Temp: %5.1fC\n\r",sensor.getTemperature()); //Print temperature 00088 printf("Pres: %5.1fmBar\n\r",sensor.getPressure()); //Print Pressure 00089 printf("LDR: %f\n\r",LDRSensor); //Print Light Level 00090 printf("Flashing Sample LED\n\r"); 00091 for (i=0;i<5;i++){ //Flash the LED 00092 SamplingLED = 1; 00093 Thread::wait(200); 00094 SamplingLED = 0; 00095 Thread::wait(200); 00096 } 00097 SamplingLED = 0; 00098 printf("------Self Test Complete------\n\r"); 00099 Thread::wait(1000); 00100 }
Generated on Tue Jul 26 2022 07:29:23 by
1.7.2