![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Plant Monitoring Project
Dependencies: mbed SHT21_ncleee WakeUp SSD1306 DHT Adafruit_TCS34725 DS1820
main.cpp@27:05fb631b1f6e, 2019-12-03 (annotated)
- Committer:
- Germaint
- Date:
- Tue Dec 03 15:36:17 2019 +0000
- Revision:
- 27:05fb631b1f6e
- Parent:
- 26:5d38b3abb89a
- Child:
- 29:29df6820812c
- Child:
- 30:0a25c02e25d9
Fix #define problems
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Germaint | 23:424b3149003b | 1 | #include "main.hh" |
Germaint | 18:d30cd2967da4 | 2 | |
Germaint | 23:424b3149003b | 3 | int main(){ |
Germaint | 23:424b3149003b | 4 | #ifdef OLED |
ludollaoo | 20:79f4ef29eafd | 5 | bouton.rise(interruption_bouton); |
Germaint | 23:424b3149003b | 6 | initOLED(); |
Germaint | 23:424b3149003b | 7 | #endif |
Germaint | 1:3fc11a745984 | 8 | |
jufray | 0:e030be8f0310 | 9 | while(1) { |
Germaint | 16:13364798fce6 | 10 | readData(); |
Germaint | 23:424b3149003b | 11 | wait(DUREE_OFF); |
jufray | 0:e030be8f0310 | 12 | } |
jufray | 0:e030be8f0310 | 13 | } |
jufray | 0:e030be8f0310 | 14 | |
Germaint | 27:05fb631b1f6e | 15 | #ifdef FLOOR_TEMPERATURE |
jufray | 0:e030be8f0310 | 16 | float temp_sol() |
jufray | 0:e030be8f0310 | 17 | { |
jufray | 0:e030be8f0310 | 18 | DS.convertTemperature(true, DS1820::all_devices); |
ludollaoo | 22:51aed3b3b452 | 19 | if (DS.unassignedProbe(D2)){ |
Germaint | 23:424b3149003b | 20 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 21 | pc.printf( "D3 not assigned\n\r"); |
Germaint | 23:424b3149003b | 22 | #endif |
jufray | 0:e030be8f0310 | 23 | } |
Germaint | 25:77322fbe298e | 24 | #ifdef DEBUG |
Germaint | 25:77322fbe298e | 25 | pc.printf("temp sol: %.1f\n\r", DS.temperature()); |
Germaint | 25:77322fbe298e | 26 | #endif |
jufray | 0:e030be8f0310 | 27 | return DS.temperature(); |
jufray | 0:e030be8f0310 | 28 | } |
Germaint | 27:05fb631b1f6e | 29 | #endif |
Germaint | 23:424b3149003b | 30 | |
Germaint | 27:05fb631b1f6e | 31 | #ifdef FLOOR_HUMIDITY |
Germaint | 1:3fc11a745984 | 32 | int fct_humidity_sol(void) |
jufray | 0:e030be8f0310 | 33 | { |
jufray | 0:e030be8f0310 | 34 | float val_min = 0.377; |
jufray | 0:e030be8f0310 | 35 | float val_max = 0.772; |
jufray | 0:e030be8f0310 | 36 | float mesure, mesure_etalonnee; |
Germaint | 1:3fc11a745984 | 37 | mesure = capteur_humidity_sol.read(); |
jufray | 0:e030be8f0310 | 38 | mesure_etalonnee = (1-((mesure - val_min)/(val_max - val_min)))*100; |
Germaint | 23:424b3149003b | 39 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 40 | pc.printf("hum sol: %d\n\r", (int) mesure_etalonnee); |
Germaint | 23:424b3149003b | 41 | #endif |
jufray | 0:e030be8f0310 | 42 | return (int) mesure_etalonnee; |
jufray | 0:e030be8f0310 | 43 | } |
Germaint | 27:05fb631b1f6e | 44 | #endif |
jufray | 0:e030be8f0310 | 45 | |
Germaint | 27:05fb631b1f6e | 46 | #ifdef RGB |
Germaint | 18:d30cd2967da4 | 47 | void fct_RGB(void) |
jufray | 0:e030be8f0310 | 48 | { |
jufray | 0:e030be8f0310 | 49 | int somme; |
jufray | 0:e030be8f0310 | 50 | uint16_t clear, red, green, blue; |
jufray | 0:e030be8f0310 | 51 | if (!RGBsens.begin()) |
jufray | 0:e030be8f0310 | 52 | { |
Germaint | 23:424b3149003b | 53 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 54 | pc.printf("No TCS34725 found ... check your connections"); |
Germaint | 23:424b3149003b | 55 | #endif |
Germaint | 15:c73d0d180cc4 | 56 | //while (1); // halt! |
jufray | 0:e030be8f0310 | 57 | } |
jufray | 0:e030be8f0310 | 58 | RGBsens.getRawData(&red, &green, &blue, &clear); |
jufray | 0:e030be8f0310 | 59 | somme = red + green + blue; |
Germaint | 18:d30cd2967da4 | 60 | pr = red*100/somme; |
Germaint | 18:d30cd2967da4 | 61 | pg = green*100/somme; |
Germaint | 18:d30cd2967da4 | 62 | pb = blue*100/somme; |
Germaint | 18:d30cd2967da4 | 63 | lum = clear; |
Germaint | 23:424b3149003b | 64 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 65 | pc.printf("luminosite : %d \n\r", lum); |
Germaint | 23:424b3149003b | 66 | pc.printf("rouge:%d vert:%d bleu:%d \n\r", pr, pg, pb); |
Germaint | 23:424b3149003b | 67 | #endif |
jufray | 0:e030be8f0310 | 68 | } |
Germaint | 27:05fb631b1f6e | 69 | #endif |
jufray | 0:e030be8f0310 | 70 | |
Germaint | 27:05fb631b1f6e | 71 | #ifdef SIGFOX |
Germaint | 16:13364798fce6 | 72 | void sendDataSigfox(void){ |
Germaint | 23:424b3149003b | 73 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 74 | pc.printf("Sending Data to Sigfox \n\r"); |
Germaint | 23:424b3149003b | 75 | #endif |
Germaint | 16:13364798fce6 | 76 | short tempSol_short, tempAir_short; |
Germaint | 16:13364798fce6 | 77 | tempSol_short = (short)(temperature_sol*10); |
Germaint | 16:13364798fce6 | 78 | tempAir_short = (short)(temperature_air*10); |
jufray | 0:e030be8f0310 | 79 | |
Germaint | 23:424b3149003b | 80 | wisol.printf("AT$SF=%04x%02x%04x%02x%04x%02x%02x%02x\r\n",tempSol_short, humidity_sol, tempAir_short, humidity_air, lum, pr, pg, pb); |
Germaint | 16:13364798fce6 | 81 | } |
Germaint | 27:05fb631b1f6e | 82 | #endif |
Germaint | 27:05fb631b1f6e | 83 | |
Germaint | 27:05fb631b1f6e | 84 | #ifdef OLED |
Germaint | 2:0bfe25431e8e | 85 | void oledData(void){ |
Germaint | 23:424b3149003b | 86 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 87 | pc.printf("Displaying Data\r\n"); |
Germaint | 23:424b3149003b | 88 | #endif |
Germaint | 18:d30cd2967da4 | 89 | if(!oled_on){ |
Germaint | 18:d30cd2967da4 | 90 | oled.wake(); |
Germaint | 18:d30cd2967da4 | 91 | oled_on = 1; |
Germaint | 18:d30cd2967da4 | 92 | } |
Germaint | 16:13364798fce6 | 93 | oled.cls(0,1); |
Germaint | 2:0bfe25431e8e | 94 | oled.locate(0,0); |
Germaint | 2:0bfe25431e8e | 95 | oled.printf("AIR T : %.1f", temperature_air); |
Germaint | 2:0bfe25431e8e | 96 | oled.locate(1,0); |
Germaint | 2:0bfe25431e8e | 97 | oled.printf("AIR H : %d", humidity_air); |
Germaint | 2:0bfe25431e8e | 98 | oled.locate(3,0); |
Germaint | 2:0bfe25431e8e | 99 | oled.printf("FLOOR T : %.1f", temperature_sol); |
Germaint | 2:0bfe25431e8e | 100 | oled.locate(4,0); |
Germaint | 2:0bfe25431e8e | 101 | oled.printf("FLOOR H : %d", humidity_sol); |
Germaint | 2:0bfe25431e8e | 102 | oled.locate(6,0); |
Germaint | 2:0bfe25431e8e | 103 | oled.printf("Light : %d", lum); |
Germaint | 2:0bfe25431e8e | 104 | oled.locate(7,0); |
Germaint | 2:0bfe25431e8e | 105 | oled.printf("R %d G %d B %d", pr, pg, pb); |
Germaint | 2:0bfe25431e8e | 106 | oled.redraw(); |
Germaint | 2:0bfe25431e8e | 107 | } |
Germaint | 27:05fb631b1f6e | 108 | #endif |
jufray | 0:e030be8f0310 | 109 | |
Germaint | 16:13364798fce6 | 110 | void readData(void){ |
Germaint | 23:424b3149003b | 111 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 112 | pc.printf("Reading Data\n\r"); |
Germaint | 23:424b3149003b | 113 | #endif |
Germaint | 23:424b3149003b | 114 | #ifdef FLOOR_TEMPERATURE |
Germaint | 16:13364798fce6 | 115 | temperature_sol = temp_sol(); |
Germaint | 23:424b3149003b | 116 | #endif |
Germaint | 23:424b3149003b | 117 | #ifdef FLOOR_HUMIDITY |
Germaint | 16:13364798fce6 | 118 | humidity_sol = fct_humidity_sol(); |
Germaint | 23:424b3149003b | 119 | #endif |
Germaint | 23:424b3149003b | 120 | #ifdef AIR_PARAMETERS |
Germaint | 23:424b3149003b | 121 | temperature_air = sht.readTemp(); |
ludollaoo | 20:79f4ef29eafd | 122 | humidity_air = sht.readHumidity(); |
Germaint | 23:424b3149003b | 123 | #endif |
Germaint | 23:424b3149003b | 124 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 125 | printf("hum air: %d\n\r", humidity_air); |
Germaint | 23:424b3149003b | 126 | printf("temp air: %.1f\n\r", temperature_air); |
Germaint | 23:424b3149003b | 127 | #endif |
Germaint | 23:424b3149003b | 128 | #ifdef RGB |
Germaint | 18:d30cd2967da4 | 129 | fct_RGB(); |
Germaint | 23:424b3149003b | 130 | #endif |
Germaint | 23:424b3149003b | 131 | #ifdef SIGFOX |
Germaint | 16:13364798fce6 | 132 | sendDataSigfox(); |
Germaint | 23:424b3149003b | 133 | #endif |
Germaint | 23:424b3149003b | 134 | #ifdef OLED |
Germaint | 18:d30cd2967da4 | 135 | if(oled_on) |
Germaint | 18:d30cd2967da4 | 136 | oledData(); |
Germaint | 23:424b3149003b | 137 | #endif |
Germaint | 16:13364798fce6 | 138 | } |
jufray | 0:e030be8f0310 | 139 | |
Germaint | 18:d30cd2967da4 | 140 | void interruption_bouton(){ |
Germaint | 18:d30cd2967da4 | 141 | bouton.disable_irq(); |
Germaint | 23:424b3149003b | 142 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 143 | pc.printf("Button interrupt\r\n"); |
Germaint | 23:424b3149003b | 144 | #endif |
Germaint | 27:05fb631b1f6e | 145 | #ifdef OLED |
Germaint | 18:d30cd2967da4 | 146 | if(!oled_on){ |
Germaint | 18:d30cd2967da4 | 147 | oledData(); |
Germaint | 18:d30cd2967da4 | 148 | timeScreen.attach(&turnOffScreen,DUREE_ECRAN_ON); |
Germaint | 18:d30cd2967da4 | 149 | } |
Germaint | 27:05fb631b1f6e | 150 | #endif |
Germaint | 18:d30cd2967da4 | 151 | bouton.enable_irq(); |
Germaint | 18:d30cd2967da4 | 152 | } |
Germaint | 16:13364798fce6 | 153 | |
Germaint | 27:05fb631b1f6e | 154 | #ifdef OLED |
Germaint | 18:d30cd2967da4 | 155 | void turnOffScreen(void){ |
Germaint | 23:424b3149003b | 156 | #ifdef DEBUG |
Germaint | 23:424b3149003b | 157 | pc.printf("Turning off screen \n\r"); |
Germaint | 23:424b3149003b | 158 | #endif |
Germaint | 18:d30cd2967da4 | 159 | timeScreen.detach(); |
Germaint | 18:d30cd2967da4 | 160 | oled_on = 0; |
Germaint | 18:d30cd2967da4 | 161 | oled.sleep(); |
Germaint | 23:424b3149003b | 162 | } |
Germaint | 27:05fb631b1f6e | 163 | #endif |
Germaint | 23:424b3149003b | 164 | |
Germaint | 27:05fb631b1f6e | 165 | #ifdef OLED |
Germaint | 23:424b3149003b | 166 | void initOLED(void){ |
Germaint | 23:424b3149003b | 167 | oled.wake(); |
Germaint | 23:424b3149003b | 168 | oled.init(); |
Germaint | 23:424b3149003b | 169 | oled.cls(0,1); |
Germaint | 23:424b3149003b | 170 | oled.locate(4,4); |
Germaint | 23:424b3149003b | 171 | oled.printf("2PA2S"); |
Germaint | 23:424b3149003b | 172 | oled.redraw(); |
Germaint | 23:424b3149003b | 173 | wait(1); |
Germaint | 23:424b3149003b | 174 | oled.cls(0,1); |
Germaint | 23:424b3149003b | 175 | oled.sleep(); |
Germaint | 27:05fb631b1f6e | 176 | } |
Germaint | 27:05fb631b1f6e | 177 | #endif |