kjdas

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_sd_0801 by Calvin Kalintra

Committer:
ckalintra
Date:
Sat Jan 06 17:28:05 2018 +0000
Revision:
0:7023c3f98f36
Child:
1:dc21a6fce3af
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 0:7023c3f98f36 7 float data_temp [120], data_press[120], data_light[120];
ckalintra 0:7023c3f98f36 8 BMP280 bmp(D14,D15,0x76);
ckalintra 0:7023c3f98f36 9
ckalintra 0:7023c3f98f36 10 AnalogIn LDR(A0);
ckalintra 0:7023c3f98f36 11 int counterw = 0, full = 0, day, month, year, leap;
ckalintra 0:7023c3f98f36 12
ckalintra 0:7023c3f98f36 13 void time_rule()
ckalintra 0:7023c3f98f36 14 {
ckalintra 0:7023c3f98f36 15 if (ss == 10)
ckalintra 0:7023c3f98f36 16 {
ckalintra 0:7023c3f98f36 17 ss = 0;
ckalintra 0:7023c3f98f36 18 s++;
ckalintra 0:7023c3f98f36 19 }
ckalintra 0:7023c3f98f36 20
ckalintra 0:7023c3f98f36 21 if (s == 6 && ss == 0)
ckalintra 0:7023c3f98f36 22 {
ckalintra 0:7023c3f98f36 23 ss = 1;
ckalintra 0:7023c3f98f36 24 s = 0;
ckalintra 0:7023c3f98f36 25 mmi++;
ckalintra 0:7023c3f98f36 26 }
ckalintra 0:7023c3f98f36 27
ckalintra 0:7023c3f98f36 28 if (mmi == 10)
ckalintra 0:7023c3f98f36 29 {
ckalintra 0:7023c3f98f36 30 mmi = 0;
ckalintra 0:7023c3f98f36 31 mi++;
ckalintra 0:7023c3f98f36 32 }
ckalintra 0:7023c3f98f36 33
ckalintra 0:7023c3f98f36 34 if (mi == 6 && mmi == 0)
ckalintra 0:7023c3f98f36 35 {
ckalintra 0:7023c3f98f36 36 mi = 0;
ckalintra 0:7023c3f98f36 37 mmi = 1;
ckalintra 0:7023c3f98f36 38 hh++;
ckalintra 0:7023c3f98f36 39 }
ckalintra 0:7023c3f98f36 40
ckalintra 0:7023c3f98f36 41 if (hh == 10)
ckalintra 0:7023c3f98f36 42 {
ckalintra 0:7023c3f98f36 43 hh = 0;
ckalintra 0:7023c3f98f36 44 h++;
ckalintra 0:7023c3f98f36 45 }
ckalintra 0:7023c3f98f36 46
ckalintra 0:7023c3f98f36 47 if(h == 2 && hh == 4)
ckalintra 0:7023c3f98f36 48 {
ckalintra 0:7023c3f98f36 49 h = 0;
ckalintra 0:7023c3f98f36 50 hh = 0;
ckalintra 0:7023c3f98f36 51 dd++;
ckalintra 0:7023c3f98f36 52 }
ckalintra 0:7023c3f98f36 53 }
ckalintra 0:7023c3f98f36 54
ckalintra 0:7023c3f98f36 55
ckalintra 0:7023c3f98f36 56 void date_rule()
ckalintra 0:7023c3f98f36 57 {
ckalintra 0:7023c3f98f36 58 if (mm == 10)
ckalintra 0:7023c3f98f36 59 {
ckalintra 0:7023c3f98f36 60 mm = 0;
ckalintra 0:7023c3f98f36 61 m++;
ckalintra 0:7023c3f98f36 62 }
ckalintra 0:7023c3f98f36 63
ckalintra 0:7023c3f98f36 64 if (m == 1 && mm == 3)
ckalintra 0:7023c3f98f36 65 {
ckalintra 0:7023c3f98f36 66 m = 0;
ckalintra 0:7023c3f98f36 67 mm = 1;
ckalintra 0:7023c3f98f36 68 yyyy++;
ckalintra 0:7023c3f98f36 69 }
ckalintra 0:7023c3f98f36 70
ckalintra 0:7023c3f98f36 71 if (yyyy== 10)
ckalintra 0:7023c3f98f36 72 {
ckalintra 0:7023c3f98f36 73 yyyy = 0;
ckalintra 0:7023c3f98f36 74 yyy++;
ckalintra 0:7023c3f98f36 75 }
ckalintra 0:7023c3f98f36 76 if (yyy == 10)
ckalintra 0:7023c3f98f36 77 {
ckalintra 0:7023c3f98f36 78 yyy = 0;
ckalintra 0:7023c3f98f36 79 yy++;
ckalintra 0:7023c3f98f36 80 }
ckalintra 0:7023c3f98f36 81 if (yy == 10)
ckalintra 0:7023c3f98f36 82 {
ckalintra 0:7023c3f98f36 83 yy = 0;
ckalintra 0:7023c3f98f36 84 y++;
ckalintra 0:7023c3f98f36 85 }
ckalintra 0:7023c3f98f36 86
ckalintra 0:7023c3f98f36 87 }
ckalintra 0:7023c3f98f36 88
ckalintra 0:7023c3f98f36 89
ckalintra 0:7023c3f98f36 90 void day_check()
ckalintra 0:7023c3f98f36 91 {
ckalintra 0:7023c3f98f36 92 day = 10*d + dd;
ckalintra 0:7023c3f98f36 93 month = mi*10+mmi;
ckalintra 0:7023c3f98f36 94 year = y*1000+yy*100+yyy*10+yyyy;
ckalintra 0:7023c3f98f36 95 if(month == 1||3||5||7||8||10||12)
ckalintra 0:7023c3f98f36 96 {
ckalintra 0:7023c3f98f36 97 if (day == 32)
ckalintra 0:7023c3f98f36 98 {
ckalintra 0:7023c3f98f36 99 mm++;
ckalintra 0:7023c3f98f36 100 d = 0;
ckalintra 0:7023c3f98f36 101 dd = 1;
ckalintra 0:7023c3f98f36 102 }
ckalintra 0:7023c3f98f36 103 }
ckalintra 0:7023c3f98f36 104
ckalintra 0:7023c3f98f36 105 else if(month == 4||6||9||11 )
ckalintra 0:7023c3f98f36 106 {
ckalintra 0:7023c3f98f36 107 if (day == 31)
ckalintra 0:7023c3f98f36 108 {
ckalintra 0:7023c3f98f36 109 mm++;
ckalintra 0:7023c3f98f36 110 d = 0;
ckalintra 0:7023c3f98f36 111 dd = 1;
ckalintra 0:7023c3f98f36 112 }
ckalintra 0:7023c3f98f36 113 }
ckalintra 0:7023c3f98f36 114
ckalintra 0:7023c3f98f36 115 else if(month == 2)
ckalintra 0:7023c3f98f36 116 {
ckalintra 0:7023c3f98f36 117 leap = year % 4;
ckalintra 0:7023c3f98f36 118 if(leap == 0)
ckalintra 0:7023c3f98f36 119 {
ckalintra 0:7023c3f98f36 120 if (day == 30)
ckalintra 0:7023c3f98f36 121 {
ckalintra 0:7023c3f98f36 122 mm++;
ckalintra 0:7023c3f98f36 123 d = 0;
ckalintra 0:7023c3f98f36 124 dd = 1;
ckalintra 0:7023c3f98f36 125 }
ckalintra 0:7023c3f98f36 126 }
ckalintra 0:7023c3f98f36 127 else
ckalintra 0:7023c3f98f36 128 {
ckalintra 0:7023c3f98f36 129 if (day == 29)
ckalintra 0:7023c3f98f36 130 {
ckalintra 0:7023c3f98f36 131 mm++;
ckalintra 0:7023c3f98f36 132 d = 0;
ckalintra 0:7023c3f98f36 133 dd = 1;
ckalintra 0:7023c3f98f36 134 }
ckalintra 0:7023c3f98f36 135 }
ckalintra 0:7023c3f98f36 136 }
ckalintra 0:7023c3f98f36 137 date_rule();
ckalintra 0:7023c3f98f36 138 }
ckalintra 0:7023c3f98f36 139
ckalintra 0:7023c3f98f36 140
ckalintra 0:7023c3f98f36 141
ckalintra 0:7023c3f98f36 142
ckalintra 0:7023c3f98f36 143 void getdata()
ckalintra 0:7023c3f98f36 144 {
ckalintra 0:7023c3f98f36 145 tempf = bmp.getTemperature();
ckalintra 0:7023c3f98f36 146 //tempf = tempf*-1;
ckalintra 0:7023c3f98f36 147 pressuref = bmp.getPressure();
ckalintra 0:7023c3f98f36 148 lvl = LDR;
ckalintra 0:7023c3f98f36 149 }
ckalintra 0:7023c3f98f36 150
ckalintra 0:7023c3f98f36 151 void store()
ckalintra 0:7023c3f98f36 152 {
ckalintra 0:7023c3f98f36 153 data_temp[counterw] = tempf;
ckalintra 0:7023c3f98f36 154 data_press[counterw] = pressuref;
ckalintra 0:7023c3f98f36 155 data_light[counterw] = lvl;
ckalintra 0:7023c3f98f36 156
ckalintra 0:7023c3f98f36 157 if (counterw == 120)
ckalintra 0:7023c3f98f36 158 {
ckalintra 0:7023c3f98f36 159 counterw = 0;
ckalintra 0:7023c3f98f36 160 full = 1;
ckalintra 0:7023c3f98f36 161 }
ckalintra 0:7023c3f98f36 162 counterw++;
ckalintra 0:7023c3f98f36 163 }
ckalintra 0:7023c3f98f36 164
ckalintra 0:7023c3f98f36 165
ckalintra 0:7023c3f98f36 166