supprimer les warnings
Dependencies: mbed projet_embarque WakeUp SigfoxToiture DHT DS1820
main.cpp@2:17db0f2dea0b, 2019-10-01 (annotated)
- Committer:
- 3874313
- Date:
- Tue Oct 01 15:02:26 2019 +0000
- Revision:
- 2:17db0f2dea0b
- Parent:
- 1:61623b5d178c
- Child:
- 3:6af60ea9a240
utilisation de float
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liuyingshan | 0:8fc2f1479292 | 1 | #include"mbed.h" |
liuyingshan | 0:8fc2f1479292 | 2 | #include"DS1820.h" |
liuyingshan | 0:8fc2f1479292 | 3 | #include"DHT.h" |
liuyingshan | 0:8fc2f1479292 | 4 | #include "TCS34725.h" |
liuyingshan | 0:8fc2f1479292 | 5 | #include "Sigfox.h" |
liuyingshan | 0:8fc2f1479292 | 6 | #include <math.h> |
liuyingshan | 0:8fc2f1479292 | 7 | |
liuyingshan | 0:8fc2f1479292 | 8 | #define GROVE_MOIST_MIN 0 |
liuyingshan | 0:8fc2f1479292 | 9 | #define GROVE_MOIST_MAX 0.55 |
liuyingshan | 0:8fc2f1479292 | 10 | #define LOG_RANGE 5 |
liuyingshan | 0:8fc2f1479292 | 11 | #define RAW_RANGE 1024 |
liuyingshan | 0:8fc2f1479292 | 12 | |
liuyingshan | 0:8fc2f1479292 | 13 | |
liuyingshan | 0:8fc2f1479292 | 14 | float Temp_Sol; |
liuyingshan | 0:8fc2f1479292 | 15 | float Temp_Air; |
liuyingshan | 0:8fc2f1479292 | 16 | float Humi_Air; |
liuyingshan | 0:8fc2f1479292 | 17 | float Humi_Sol; |
liuyingshan | 0:8fc2f1479292 | 18 | float Lumiere; |
liuyingshan | 0:8fc2f1479292 | 19 | uint16_t r; |
liuyingshan | 0:8fc2f1479292 | 20 | uint16_t g; |
liuyingshan | 0:8fc2f1479292 | 21 | uint16_t b; |
liuyingshan | 0:8fc2f1479292 | 22 | uint16_t c; |
liuyingshan | 0:8fc2f1479292 | 23 | |
liuyingshan | 0:8fc2f1479292 | 24 | DHT dht22(D6,DHT22);//pin,type |
liuyingshan | 0:8fc2f1479292 | 25 | DS1820 ds1820(A0);//pin |
liuyingshan | 0:8fc2f1479292 | 26 | TCS34725 tcs34725(D4,D5); //I2C sda and scl |
liuyingshan | 0:8fc2f1479292 | 27 | AnalogIn humigrove(A1); |
liuyingshan | 0:8fc2f1479292 | 28 | AnalogIn lumiere(A5); |
3874313 | 2:17db0f2dea0b | 29 | DigitalOut ledTest(LED1); |
liuyingshan | 0:8fc2f1479292 | 30 | |
liuyingshan | 0:8fc2f1479292 | 31 | void ReadTempHumiAir(){ |
liuyingshan | 0:8fc2f1479292 | 32 | int err=1; |
liuyingshan | 0:8fc2f1479292 | 33 | while(err!=0){ |
liuyingshan | 0:8fc2f1479292 | 34 | err=dht22.readData(); |
3874313 | 2:17db0f2dea0b | 35 | ledTest = 1; |
liuyingshan | 0:8fc2f1479292 | 36 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 37 | } |
liuyingshan | 0:8fc2f1479292 | 38 | if(err==0){ |
liuyingshan | 0:8fc2f1479292 | 39 | Temp_Air= dht22.ReadTemperature(CELCIUS); |
liuyingshan | 0:8fc2f1479292 | 40 | Humi_Air=dht22.ReadHumidity(); |
3874313 | 2:17db0f2dea0b | 41 | ledTest = 0; |
liuyingshan | 0:8fc2f1479292 | 42 | } |
3874313 | 2:17db0f2dea0b | 43 | |
liuyingshan | 0:8fc2f1479292 | 44 | } |
liuyingshan | 0:8fc2f1479292 | 45 | |
liuyingshan | 0:8fc2f1479292 | 46 | void ReadTempSol(){ |
liuyingshan | 0:8fc2f1479292 | 47 | if (ds1820.begin()) { |
liuyingshan | 0:8fc2f1479292 | 48 | ds1820.startConversion(); // start temperature conversion from analog to digital |
liuyingshan | 0:8fc2f1479292 | 49 | wait(1); // let DS1820 complete the temperature conversion |
liuyingshan | 0:8fc2f1479292 | 50 | Temp_Sol = ds1820.read(); |
liuyingshan | 0:8fc2f1479292 | 51 | } |
liuyingshan | 0:8fc2f1479292 | 52 | } |
liuyingshan | 0:8fc2f1479292 | 53 | |
liuyingshan | 0:8fc2f1479292 | 54 | void ReadRGBC(){ |
liuyingshan | 0:8fc2f1479292 | 55 | if(tcs34725.init(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_60X)){ |
liuyingshan | 0:8fc2f1479292 | 56 | tcs34725.getColor(r,g,b,c); |
liuyingshan | 0:8fc2f1479292 | 57 | r/=256; |
liuyingshan | 0:8fc2f1479292 | 58 | g/=256; |
liuyingshan | 0:8fc2f1479292 | 59 | b/=256; |
liuyingshan | 0:8fc2f1479292 | 60 | c/=256; |
liuyingshan | 0:8fc2f1479292 | 61 | } |
liuyingshan | 0:8fc2f1479292 | 62 | } |
liuyingshan | 0:8fc2f1479292 | 63 | |
liuyingshan | 0:8fc2f1479292 | 64 | void ReadHumiSol(){ |
liuyingshan | 0:8fc2f1479292 | 65 | float grove_moist=humigrove.read(); |
liuyingshan | 0:8fc2f1479292 | 66 | Humi_Sol= ((grove_moist-GROVE_MOIST_MIN) / (GROVE_MOIST_MAX - GROVE_MOIST_MIN)) * 100; |
liuyingshan | 0:8fc2f1479292 | 67 | } |
liuyingshan | 0:8fc2f1479292 | 68 | |
liuyingshan | 0:8fc2f1479292 | 69 | void ReadLumi(){ |
liuyingshan | 0:8fc2f1479292 | 70 | int raw=lumiere.read(); |
liuyingshan | 0:8fc2f1479292 | 71 | float loglux=raw*LOG_RANGE/RAW_RANGE; |
liuyingshan | 0:8fc2f1479292 | 72 | Lumiere=pow(10,loglux); |
liuyingshan | 0:8fc2f1479292 | 73 | } |
liuyingshan | 0:8fc2f1479292 | 74 | |
liuyingshan | 0:8fc2f1479292 | 75 | int main(){ |
liuyingshan | 0:8fc2f1479292 | 76 | //Serial at(D1,D0); |
liuyingshan | 0:8fc2f1479292 | 77 | Sigfox sigfox(D1,D0); |
liuyingshan | 0:8fc2f1479292 | 78 | |
liuyingshan | 0:8fc2f1479292 | 79 | while(1){ |
liuyingshan | 0:8fc2f1479292 | 80 | ReadTempHumiAir(); |
liuyingshan | 0:8fc2f1479292 | 81 | ReadTempSol(); |
liuyingshan | 0:8fc2f1479292 | 82 | ReadRGBC(); |
liuyingshan | 0:8fc2f1479292 | 83 | ReadHumiSol(); |
3874313 | 2:17db0f2dea0b | 84 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 85 | ReadLumi(); |
liuyingshan | 0:8fc2f1479292 | 86 | wait(1); |
liuyingshan | 0:8fc2f1479292 | 87 | printf("R:%d, G:%d, B:%d\n\r", r, g, b); |
3874313 | 2:17db0f2dea0b | 88 | sigfox.send((s16)(Temp_Air*10),(u16)(Humi_Air*10),(s16)(Temp_Sol*10),(u16)(Humi_Sol*10), |
liuyingshan | 0:8fc2f1479292 | 89 | (u8)Lumiere,(u8)r,(u8)g,(u8)b); |
liuyingshan | 0:8fc2f1479292 | 90 | wait(120); |
3874313 | 2:17db0f2dea0b | 91 | /*printf("R:%d, G:%d, B:%d, temp: %f, hum: %f\r", r, g, b, Temp_Air, Humi_Air); |
3874313 | 2:17db0f2dea0b | 92 | wait(0.5);*/ |
liuyingshan | 0:8fc2f1479292 | 93 | } |
liuyingshan | 0:8fc2f1479292 | 94 | } |