Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:f9245fb53737, committed 2018-12-03
- Comitter:
- jsa1969
- Date:
- Mon Dec 03 15:07:25 2018 +0000
- Parent:
- 0:cef60cc92da0
- Child:
- 2:544117df8c65
- Commit message:
- add humidity physics
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Physics/physics.cpp Mon Dec 03 15:07:25 2018 +0000
@@ -0,0 +1,18 @@
+#include "physics.h"
+
+int Physics::absHumidity(int relHumidity, int temperature){
+ const float tmpFloat = (float)temperature;
+ return (int)(relHumidity * saettigung(tmpFloat));
+}
+
+float Physics::saettigung(float tmpFloat) {
+ float dd = saettigungsdampfdruck(tmpFloat);
+ return dd/(4.6152*(273.15+tmpFloat));
+}
+
+float Physics::saettigungsdampfdruck(float tmpFloat){
+ const float t1 = 16.62 * tmpFloat;
+ const float t2 = 243.12 + tmpFloat;
+ const float factor1 = expf(t1 / t2);
+ return 61120 * factor1;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Physics/physics.h Mon Dec 03 15:07:25 2018 +0000
@@ -0,0 +1,17 @@
+#include "mbed.h"
+#include "MicroBit.h"
+
+#ifndef PHYSICS_H
+#define PHYSICS_H
+
+class Physics {
+ public:
+ static int absHumidity(int relHumidity, int temperature);
+
+ private:
+ static float saettigung(float tmpFloat);
+ static float saettigungsdampfdruck(float tmpFloat);
+
+};
+
+#endif //
\ No newline at end of file
--- a/main.cpp Mon Dec 03 13:19:07 2018 +0000
+++ b/main.cpp Mon Dec 03 15:07:25 2018 +0000
@@ -26,34 +26,49 @@
#include "MicroBit.h"
#include "bme680.h"
+#include "physics.h"
MicroBit uBit;
Bme680* bme680;
+struct bme680_field_data* bme680Data;
bool cancelMeasureLoop=false;
+float tmp=0.0;
-int measure(){
- struct bme680_field_data* data = new struct bme680_field_data;
- return bme680->measure(
- data,
- uBit.thermometer.getTemperature(),
- 750, 150);
+int measureBme680(){
+ if (bme680!=NULL && bme680Data!=NULL) {
+ return bme680->measure(
+ bme680Data,
+ uBit.thermometer.getTemperature(),
+ 750, 350);
+ } else {
+ return BME680_E_DEV_NOT_FOUND;
+ }
}
void onButtonA(MicroBitEvent evt)
{
+ /*
if (bme680!=NULL) {
while (!cancelMeasureLoop){
- uBit.display.scroll(measure());
+ uBit.display.scroll(measureBme680());
uBit.sleep(500);
}
cancelMeasureLoop=false;
}
+ */
+ //uBit.display.scroll((int)Physics::saettigungsdampfdruck(0.0));
+ tmp += 1.0;
+ uBit.display.scroll((int)tmp);
+ uBit.display.scroll(Physics::absHumidity(100,tmp));
}
void onButtonB(MicroBitEvent evt)
{
- cancelMeasureLoop=true;
+ //cancelMeasureLoop=true;
+ tmp -= 1.0;
+ uBit.display.scroll((int)tmp);
+ uBit.display.scroll((int)Physics::absHumidity(100,tmp));
}
int main()
@@ -72,7 +87,11 @@
uBit.display.scroll(code);
} else {
uBit.display.scroll("bme:");
- uBit.display.scroll(measure());
+ bme680Data = new struct bme680_field_data;
+ uBit.display.scroll(bme680->measure(
+ bme680Data,
+ uBit.thermometer.getTemperature(),
+ 100, 100));
}
// If main exits, there may still be other fibers running or registered event handlers etc.
// Simply release this fiber, which will mean we enter the scheduler. Worse case, we then