Simple Mbed example of sleepy program reading OPT3001 and BME280 sensors

Dependencies:   BME280

Files at this revision

API Documentation at this revision

Comitter:
olegart
Date:
Thu Aug 16 20:22:45 2018 +0000
Commit message:
Let's call it release

Changed in this revision

BME280.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_opt3001.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME280.lib	Thu Aug 16 20:22:45 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/MACRUM/code/BME280/#c1f1647004c4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Aug 16 20:22:45 2018 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+#include "BME280.h"
+#include "OPT3001.h"
+
+DigitalOut led(LED1);
+BME280 sensor_bme(D14, D15);
+OPT3001 sensor_opt(D14, D15);
+EventQueue eventQueue(/* event count */ 50 * EVENTS_EVENT_SIZE);
+Serial pc(SERIAL_TX, SERIAL_RX);
+LowPowerTicker lpTicker;
+
+void printTemperature(void)
+{
+    pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\r\n", sensor_bme.getTemperature(), sensor_bme.getPressure(), sensor_bme.getHumidity());
+    pc.printf("%ld lux\r\n", sensor_opt.readSensor());        
+    led = !led; // Toggle LED
+}
+
+void tickerIRQ (void)
+{
+    eventQueue.call(printTemperature);
+}
+
+int main()
+{
+    pc.baud(115200);
+    
+    lpTicker.attach(tickerIRQ, 1); // every second
+    
+    while(1)
+    {
+        eventQueue.dispatch(0);
+        sleep();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Aug 16 20:22:45 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#f8b140f8d7cb226e41486c5df66ac4f3ce699219
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_opt3001.lib	Thu Aug 16 20:22:45 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/olegart/mbed_opt3001/#05eefffcdcb07bfd55eea53d5ec184fcd2bfff43