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: Air_Quality DHT mbed-src
Fork of mbed_Wiznet_W7500 by
main.cpp
00001 #include "mbed.h" 00002 #include "DHT.h" 00003 #include"Air_Quality.h" 00004 00005 AirQuality airqualitysensor; 00006 int current_quality = -1; 00007 PinName analogPin = A0; 00008 00009 DHT sensor(D4, DHT11); 00010 InterruptIn motion(D3); 00011 AnalogIn luminance(A1); 00012 00013 DigitalOut led_R(LED_RED); 00014 DigitalOut led_G(LED_GREEN); 00015 DigitalOut led_B(LED_BLUE); 00016 00017 int motion_detected = 0; 00018 00019 // Interrupt Handler 00020 void AirQualityInterrupt() 00021 { 00022 AnalogIn sensor(analogPin); 00023 airqualitysensor.last_vol = airqualitysensor.first_vol; 00024 airqualitysensor.first_vol = sensor.read()*1000; 00025 airqualitysensor.timer_index = 1; 00026 } 00027 00028 void irq_handler(void) 00029 { 00030 motion_detected = 1; 00031 } 00032 00033 int main() 00034 { 00035 int error = 0; 00036 float hum = 0.0f; 00037 float cel = 0.0f; 00038 00039 airqualitysensor.init(analogPin, AirQualityInterrupt); 00040 00041 motion.rise(&irq_handler); 00042 00043 while(1) 00044 { 00045 wait(0.3); 00046 error = sensor.readData(); 00047 00048 if (0 == error) { 00049 hum = sensor.ReadHumidity(); 00050 cel = sensor.ReadTemperature(CELCIUS); 00051 printf("1. Humidity : %4.2f\r\n\n", hum); 00052 wait(0.3); 00053 printf("2. Temperature in Celcius : %2.2f\r\n\n", cel); 00054 wait(0.3); 00055 } 00056 else { 00057 //printf("Error : %d\n", error); 00058 } 00059 00060 if(motion_detected) { 00061 motion_detected = 0; 00062 00063 printf("3. Something move!\r\n\n"); 00064 wait(0.3); 00065 } 00066 00067 if(luminance.read()){ 00068 00069 if(0.1<=luminance.read()&&luminance.read()<=0.3){ 00070 led_R=0; led_G=0; led_B=1;} // yellow LED on 00071 00072 else{ 00073 led_R=1; led_G=1; led_B=1;} // led off 00074 00075 printf("4. Luminance: %f\r\n\n", luminance.read()); 00076 wait(0.3); 00077 } 00078 else { 00079 led_R=0; led_G=0; led_B=0; // white LED on 00080 printf("4. Luminance: %f\r\n\n", luminance.read()); 00081 wait(0.3); 00082 } 00083 //air quality sensor 00084 current_quality=airqualitysensor.slope(); 00085 if (current_quality >= 0) { // if a valid data returned. 00086 if (current_quality == 0) 00087 printf(" High pollution! Force signal active\n\r\n"); 00088 else if (current_quality == 1) 00089 printf(" High pollution!\n\r\n"); 00090 else if (current_quality == 2) 00091 printf(" Low pollution!\n\n\r"); 00092 else if (current_quality == 3) 00093 printf(" Fresh air!\n\r\n"); 00094 } 00095 } 00096 }
Generated on Sun Jul 17 2022 19:52:46 by
1.7.2
