''

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_08012018a by Calvin Kalintra

Committer:
ckalintra
Date:
Tue Jan 09 11:26:15 2018 +0000
Revision:
2:c696dfd53eeb
Parent:
1:dc21a6fce3af
Child:
3:f5fe5071416a
code;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ckalintra 0:7023c3f98f36 1 #include "mbed.h"
ckalintra 0:7023c3f98f36 2 #include "BMP280.h"
ckalintra 0:7023c3f98f36 3 #include "date.h"
ckalintra 0:7023c3f98f36 4 float tempf;
ckalintra 0:7023c3f98f36 5 float pressuref;
ckalintra 0:7023c3f98f36 6 float lvl;
ckalintra 1:dc21a6fce3af 7 float data_temp [119], data_press[119], data_light[119];
ckalintra 1:dc21a6fce3af 8 int date_a[199], time_a[199], time0_a[199], date0_a[199];
ckalintra 2:c696dfd53eeb 9 BMP280 bmp(D14,D15,0x76);
ckalintra 0:7023c3f98f36 10
ckalintra 0:7023c3f98f36 11 AnalogIn LDR(A0);
ckalintra 0:7023c3f98f36 12 int counterw = 0, full = 0, day, month, year, leap;
ckalintra 0:7023c3f98f36 13
ckalintra 0:7023c3f98f36 14 void time_rule()
ckalintra 0:7023c3f98f36 15 {
ckalintra 0:7023c3f98f36 16 if (ss == 10)
ckalintra 0:7023c3f98f36 17 {
ckalintra 0:7023c3f98f36 18 ss = 0;
ckalintra 0:7023c3f98f36 19 s++;
ckalintra 0:7023c3f98f36 20 }
ckalintra 0:7023c3f98f36 21
ckalintra 0:7023c3f98f36 22 if (s == 6 && ss == 0)
ckalintra 0:7023c3f98f36 23 {
ckalintra 0:7023c3f98f36 24 ss = 1;
ckalintra 0:7023c3f98f36 25 s = 0;
ckalintra 0:7023c3f98f36 26 mmi++;
ckalintra 0:7023c3f98f36 27 }
ckalintra 0:7023c3f98f36 28
ckalintra 0:7023c3f98f36 29 if (mmi == 10)
ckalintra 0:7023c3f98f36 30 {
ckalintra 0:7023c3f98f36 31 mmi = 0;
ckalintra 0:7023c3f98f36 32 mi++;
ckalintra 0:7023c3f98f36 33 }
ckalintra 0:7023c3f98f36 34
ckalintra 0:7023c3f98f36 35 if (mi == 6 && mmi == 0)
ckalintra 0:7023c3f98f36 36 {
ckalintra 0:7023c3f98f36 37 mi = 0;
ckalintra 0:7023c3f98f36 38 mmi = 1;
ckalintra 0:7023c3f98f36 39 hh++;
ckalintra 0:7023c3f98f36 40 }
ckalintra 0:7023c3f98f36 41
ckalintra 0:7023c3f98f36 42 if (hh == 10)
ckalintra 0:7023c3f98f36 43 {
ckalintra 0:7023c3f98f36 44 hh = 0;
ckalintra 0:7023c3f98f36 45 h++;
ckalintra 0:7023c3f98f36 46 }
ckalintra 0:7023c3f98f36 47
ckalintra 0:7023c3f98f36 48 if(h == 2 && hh == 4)
ckalintra 0:7023c3f98f36 49 {
ckalintra 0:7023c3f98f36 50 h = 0;
ckalintra 0:7023c3f98f36 51 hh = 0;
ckalintra 0:7023c3f98f36 52 dd++;
ckalintra 0:7023c3f98f36 53 }
ckalintra 0:7023c3f98f36 54 }
ckalintra 0:7023c3f98f36 55
ckalintra 0:7023c3f98f36 56
ckalintra 0:7023c3f98f36 57 void date_rule()
ckalintra 0:7023c3f98f36 58 {
ckalintra 0:7023c3f98f36 59 if (mm == 10)
ckalintra 0:7023c3f98f36 60 {
ckalintra 0:7023c3f98f36 61 mm = 0;
ckalintra 0:7023c3f98f36 62 m++;
ckalintra 0:7023c3f98f36 63 }
ckalintra 0:7023c3f98f36 64
ckalintra 0:7023c3f98f36 65 if (m == 1 && mm == 3)
ckalintra 0:7023c3f98f36 66 {
ckalintra 0:7023c3f98f36 67 m = 0;
ckalintra 0:7023c3f98f36 68 mm = 1;
ckalintra 0:7023c3f98f36 69 yyyy++;
ckalintra 0:7023c3f98f36 70 }
ckalintra 0:7023c3f98f36 71
ckalintra 0:7023c3f98f36 72 if (yyyy== 10)
ckalintra 0:7023c3f98f36 73 {
ckalintra 0:7023c3f98f36 74 yyyy = 0;
ckalintra 0:7023c3f98f36 75 yyy++;
ckalintra 0:7023c3f98f36 76 }
ckalintra 0:7023c3f98f36 77 if (yyy == 10)
ckalintra 0:7023c3f98f36 78 {
ckalintra 0:7023c3f98f36 79 yyy = 0;
ckalintra 0:7023c3f98f36 80 yy++;
ckalintra 0:7023c3f98f36 81 }
ckalintra 0:7023c3f98f36 82 if (yy == 10)
ckalintra 0:7023c3f98f36 83 {
ckalintra 0:7023c3f98f36 84 yy = 0;
ckalintra 0:7023c3f98f36 85 y++;
ckalintra 0:7023c3f98f36 86 }
ckalintra 0:7023c3f98f36 87
ckalintra 0:7023c3f98f36 88 }
ckalintra 0:7023c3f98f36 89
ckalintra 1:dc21a6fce3af 90 //void day_check()
ckalintra 1:dc21a6fce3af 91 //{
ckalintra 1:dc21a6fce3af 92 // month = m*10+mm;
ckalintra 1:dc21a6fce3af 93 //
ckalintra 1:dc21a6fce3af 94 // switch (month){
ckalintra 1:dc21a6fce3af 95 // case 1:
ckalintra 1:dc21a6fce3af 96 // d = d;
ckalintra 1:dc21a6fce3af 97 // if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 98 // {
ckalintra 1:dc21a6fce3af 99 // mm++;
ckalintra 1:dc21a6fce3af 100 // d = 0;
ckalintra 1:dc21a6fce3af 101 // dd = 1;
ckalintra 1:dc21a6fce3af 102 // }
ckalintra 1:dc21a6fce3af 103 // }
ckalintra 1:dc21a6fce3af 104 // break;
ckalintra 1:dc21a6fce3af 105 //
ckalintra 1:dc21a6fce3af 106 // case 2:
ckalintra 1:dc21a6fce3af 107 // if (d == 3 %% dd == 0)
ckalintra 1:dc21a6fce3af 108 // {
ckalintra 1:dc21a6fce3af 109 // mm++;
ckalintra 1:dc21a6fce3af 110 // d = 0;
ckalintra 1:dc21a6fce3af 111 // dd = 1;
ckalintra 1:dc21a6fce3af 112 // }
ckalintra 1:dc21a6fce3af 113 // break;
ckalintra 1:dc21a6fce3af 114 // case 3: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 115 // {
ckalintra 1:dc21a6fce3af 116 // mm++;
ckalintra 1:dc21a6fce3af 117 // d = 0;
ckalintra 1:dc21a6fce3af 118 // dd = 1;
ckalintra 1:dc21a6fce3af 119 // }
ckalintra 1:dc21a6fce3af 120 // break;
ckalintra 1:dc21a6fce3af 121 // case 4: if (d == 3 %% dd == 1)
ckalintra 1:dc21a6fce3af 122 // {
ckalintra 1:dc21a6fce3af 123 // mm++;
ckalintra 1:dc21a6fce3af 124 // d = 0;
ckalintra 1:dc21a6fce3af 125 // dd = 1;
ckalintra 1:dc21a6fce3af 126 // }
ckalintra 1:dc21a6fce3af 127 // break;
ckalintra 1:dc21a6fce3af 128 // case 5: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 129 // {
ckalintra 1:dc21a6fce3af 130 // mm++;
ckalintra 1:dc21a6fce3af 131 // d = 0;
ckalintra 1:dc21a6fce3af 132 // dd = 1;
ckalintra 1:dc21a6fce3af 133 // }
ckalintra 1:dc21a6fce3af 134 // break;
ckalintra 1:dc21a6fce3af 135 // case 6 :if (d == 3 %% dd == 1)
ckalintra 1:dc21a6fce3af 136 // {
ckalintra 1:dc21a6fce3af 137 // mm++;
ckalintra 1:dc21a6fce3af 138 // d = 0;
ckalintra 1:dc21a6fce3af 139 // dd = 1;
ckalintra 1:dc21a6fce3af 140 // }
ckalintra 1:dc21a6fce3af 141 // break;
ckalintra 1:dc21a6fce3af 142 //
ckalintra 1:dc21a6fce3af 143 // case 7: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 144 // {
ckalintra 1:dc21a6fce3af 145 // mm++;
ckalintra 1:dc21a6fce3af 146 // d = 0;
ckalintra 1:dc21a6fce3af 147 // dd = 1;
ckalintra 1:dc21a6fce3af 148 // }
ckalintra 1:dc21a6fce3af 149 // break;
ckalintra 1:dc21a6fce3af 150 // case 8: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 151 // {
ckalintra 1:dc21a6fce3af 152 // mm++;
ckalintra 1:dc21a6fce3af 153 // d = 0;
ckalintra 1:dc21a6fce3af 154 // dd = 1;
ckalintra 1:dc21a6fce3af 155 // }
ckalintra 1:dc21a6fce3af 156 // break;
ckalintra 1:dc21a6fce3af 157 // case 9: if (d == 3 %% dd == 1)
ckalintra 1:dc21a6fce3af 158 // {
ckalintra 1:dc21a6fce3af 159 // mm++;
ckalintra 1:dc21a6fce3af 160 // d = 0;
ckalintra 1:dc21a6fce3af 161 // dd = 1;
ckalintra 1:dc21a6fce3af 162 // }
ckalintra 1:dc21a6fce3af 163 // break;
ckalintra 1:dc21a6fce3af 164 // case 10: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 165 // {
ckalintra 1:dc21a6fce3af 166 // mm++;
ckalintra 1:dc21a6fce3af 167 // d = 0;
ckalintra 1:dc21a6fce3af 168 // dd = 1;
ckalintra 1:dc21a6fce3af 169 // }
ckalintra 1:dc21a6fce3af 170 // break;
ckalintra 1:dc21a6fce3af 171 // case 11: if (d == 3 %% dd == 1)
ckalintra 1:dc21a6fce3af 172 // {
ckalintra 1:dc21a6fce3af 173 // mm++;
ckalintra 1:dc21a6fce3af 174 // d = 0;
ckalintra 1:dc21a6fce3af 175 // dd = 1;
ckalintra 1:dc21a6fce3af 176 // }
ckalintra 1:dc21a6fce3af 177 // break;
ckalintra 1:dc21a6fce3af 178 // case 12: if (d == 3 %% dd == 2)
ckalintra 1:dc21a6fce3af 179 // {
ckalintra 1:dc21a6fce3af 180 // mm++;
ckalintra 1:dc21a6fce3af 181 // d = 0;
ckalintra 1:dc21a6fce3af 182 // dd = 1;
ckalintra 1:dc21a6fce3af 183 // }
ckalintra 1:dc21a6fce3af 184 // break;
ckalintra 1:dc21a6fce3af 185 // }
ckalintra 1:dc21a6fce3af 186 // date_rule();
ckalintra 1:dc21a6fce3af 187 //}
ckalintra 0:7023c3f98f36 188
ckalintra 0:7023c3f98f36 189 void day_check()
ckalintra 0:7023c3f98f36 190 {
ckalintra 1:dc21a6fce3af 191 //day = 10*d + dd;
ckalintra 1:dc21a6fce3af 192 //month = m*10+mm;
ckalintra 0:7023c3f98f36 193 year = y*1000+yy*100+yyy*10+yyyy;
ckalintra 1:dc21a6fce3af 194 if((m == 0 && (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8)) || (m ==1 && (mm == 0 || mm == 2)))
ckalintra 0:7023c3f98f36 195 {
ckalintra 1:dc21a6fce3af 196 if (d == 3 && dd == 0)
ckalintra 0:7023c3f98f36 197 {
ckalintra 1:dc21a6fce3af 198 d = 3;
ckalintra 0:7023c3f98f36 199 dd = 1;
ckalintra 1:dc21a6fce3af 200 }
ckalintra 1:dc21a6fce3af 201 else if (d == 3 && dd == 2)
ckalintra 0:7023c3f98f36 202 {
ckalintra 0:7023c3f98f36 203 mm++;
ckalintra 0:7023c3f98f36 204 d = 0;
ckalintra 0:7023c3f98f36 205 dd = 1;
ckalintra 0:7023c3f98f36 206 }
ckalintra 1:dc21a6fce3af 207
ckalintra 1:dc21a6fce3af 208
ckalintra 1:dc21a6fce3af 209 }
ckalintra 1:dc21a6fce3af 210
ckalintra 1:dc21a6fce3af 211 else if((m == 0 && (mm == 4 || mm == 6 || mm == 9)) || (m ==1 && mm == 1))
ckalintra 1:dc21a6fce3af 212 {
ckalintra 1:dc21a6fce3af 213 if (d == 3 && dd == 0)
ckalintra 1:dc21a6fce3af 214 {
ckalintra 1:dc21a6fce3af 215 d = 3;
ckalintra 1:dc21a6fce3af 216 dd = 1;
ckalintra 1:dc21a6fce3af 217 }
ckalintra 1:dc21a6fce3af 218 else if (d == 3 && dd == 1)
ckalintra 1:dc21a6fce3af 219 {
ckalintra 1:dc21a6fce3af 220 mm++;
ckalintra 1:dc21a6fce3af 221 d = 0;
ckalintra 1:dc21a6fce3af 222 dd = 1;
ckalintra 1:dc21a6fce3af 223 }
ckalintra 1:dc21a6fce3af 224
ckalintra 1:dc21a6fce3af 225
ckalintra 0:7023c3f98f36 226 }
ckalintra 0:7023c3f98f36 227
ckalintra 1:dc21a6fce3af 228 else if(m == 0 && mm == 2)
ckalintra 0:7023c3f98f36 229 {
ckalintra 1:dc21a6fce3af 230 leap = year%4;
ckalintra 1:dc21a6fce3af 231 if (leap == 0)
ckalintra 0:7023c3f98f36 232 {
ckalintra 1:dc21a6fce3af 233 if (d == 3 && dd == 0)
ckalintra 1:dc21a6fce3af 234 {
ckalintra 1:dc21a6fce3af 235 mm++;
ckalintra 1:dc21a6fce3af 236 d = 0;
ckalintra 1:dc21a6fce3af 237 dd = 1;
ckalintra 1:dc21a6fce3af 238 }
ckalintra 0:7023c3f98f36 239 }
ckalintra 1:dc21a6fce3af 240 else if(leap != 0)
ckalintra 0:7023c3f98f36 241 {
ckalintra 1:dc21a6fce3af 242 if (d == 2 && dd == 9)
ckalintra 1:dc21a6fce3af 243 {
ckalintra 1:dc21a6fce3af 244 mm++;
ckalintra 1:dc21a6fce3af 245 d = 0;
ckalintra 1:dc21a6fce3af 246 dd = 1;
ckalintra 1:dc21a6fce3af 247 }
ckalintra 1:dc21a6fce3af 248 }
ckalintra 1:dc21a6fce3af 249
ckalintra 0:7023c3f98f36 250 }
ckalintra 0:7023c3f98f36 251 date_rule();
ckalintra 0:7023c3f98f36 252 }
ckalintra 0:7023c3f98f36 253
ckalintra 0:7023c3f98f36 254
ckalintra 0:7023c3f98f36 255
ckalintra 0:7023c3f98f36 256
ckalintra 0:7023c3f98f36 257 void getdata()
ckalintra 0:7023c3f98f36 258 {
ckalintra 0:7023c3f98f36 259 tempf = bmp.getTemperature();
ckalintra 0:7023c3f98f36 260 //tempf = tempf*-1;
ckalintra 0:7023c3f98f36 261 pressuref = bmp.getPressure();
ckalintra 0:7023c3f98f36 262 lvl = LDR;
ckalintra 1:dc21a6fce3af 263
ckalintra 0:7023c3f98f36 264 }
ckalintra 0:7023c3f98f36 265
ckalintra 0:7023c3f98f36 266 void store()
ckalintra 0:7023c3f98f36 267 {
ckalintra 0:7023c3f98f36 268 data_temp[counterw] = tempf;
ckalintra 0:7023c3f98f36 269 data_press[counterw] = pressuref;
ckalintra 0:7023c3f98f36 270 data_light[counterw] = lvl;
ckalintra 1:dc21a6fce3af 271 date_a[counterw] = dd*1000000+m*100000+mm*10000+y*1000+yy*100+yyy*10+yyyy;
ckalintra 1:dc21a6fce3af 272 time_a[counterw] = ss*10000+mi*1000+mmi*100+h*10+hh;
ckalintra 1:dc21a6fce3af 273 date0_a[counterw] = d;
ckalintra 1:dc21a6fce3af 274 time0_a[counterw] = s;
ckalintra 1:dc21a6fce3af 275 if (counterw == 119)
ckalintra 0:7023c3f98f36 276 {
ckalintra 0:7023c3f98f36 277 counterw = 0;
ckalintra 0:7023c3f98f36 278 full = 1;
ckalintra 0:7023c3f98f36 279 }
ckalintra 0:7023c3f98f36 280 counterw++;
ckalintra 0:7023c3f98f36 281 }
ckalintra 0:7023c3f98f36 282
ckalintra 0:7023c3f98f36 283
ckalintra 0:7023c3f98f36 284