my coursework
Dependencies: CheckRTC LPS25H hts221
Fork of ELEC350-extended-referral1 by
Revision 48:614f8821ccca, committed 2017-11-23
- Comitter:
- spanesar
- Date:
- Thu Nov 23 13:16:23 2017 +0000
- Parent:
- 47:12f18a4527d8
- Child:
- 49:a39eacfcd968
- Commit message:
- 120 readings coming out as zero?
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 23 11:50:35 2017 +0000
+++ b/main.cpp Thu Nov 23 13:16:23 2017 +0000
@@ -25,6 +25,7 @@
int count = 0;
char *buf;
size_t sz;
+int oldest;
typedef struct {
float temp;
@@ -32,7 +33,7 @@
float humid;
} measurement;
-measurement buffer [120];
+measurement buffer[120];
LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR);
HTS221 humidity(I2C_SDA, I2C_SCL);
@@ -55,9 +56,9 @@
{
//begin function
while (true) {//begin while true
- char buffer [128];
- scanf("%127s", buffer);
- string buffer_str(buffer);
+ char strbuffer [128];
+ scanf("%127s", strbuffer);
+ string buffer_str(strbuffer);
char date [32];
strftime(date, 32, "%Y/%m/%d %a", localtime(&seconds));
char time [32];
@@ -66,7 +67,11 @@
if(buffer_str=="READALL") {//begin if buffer readall
// displays all the variables of time, date, temperature, humidity and all the barometric readings to the serial
- printf("%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, barometer.pressure(), barometer.temperature());
+ for (int i = 0; i <120; i++) {
+ //printf("%s, %s, %4.2fC , %3.1f%%, %6.1f, %4.1f\n\r", time, date, tempCelsius, humi, buffer[i].humid, buffer[i].press, buffer[i].temp, barometer.temperature());
+ //measurement test=buffer[i];
+ printf("%f %f %f \n\r",buffer[i].humid, buffer[i].press, buffer[i].temp);
+ }
myled = 1; // LED is ON
Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds!
myled = 0; // LED is OFF
@@ -126,24 +131,28 @@
Thread::signal_wait(99);
//Get samples
measurement m;
-
-
+
+
float pressure = barometer.pressure();
- m.pressure = pressure;
+ m.press = pressure;
float temp;
- float humidity;
- humidity.ReadTempHumi(&temp, &humidity); // reads temperature and humity levels
- m.humidity = humidity;
- m.temperature = temp;
-
+ float humidityval;
+ humidity.ReadTempHumi(&temp, &humidityval); // reads temperature and humity levels
+ m.humid = humidityval;
+ m.temp = temp;
+
buffer[oldest] = m;
-
+
//update oldest
oldest++;
//wrap back to zero if at the end
+ if (oldest>120) {
+ oldest = 0;
+ }
+
//TO DO
-
+
}
