This project can be used to measure UV light levels. It uses an ML8511 UV sensors and outputs its value over BLE in units of mW/cm^2

Revision:
1:ab9f0e572c98
Parent:
0:6d4b6c56a7ad
--- a/main.cpp	Sat Aug 22 15:21:53 2020 +0000
+++ b/main.cpp	Thu Aug 27 12:42:55 2020 +0000
@@ -15,22 +15,25 @@
  */
 
 #include "mbed.h"
+#include "UVSensor.h"
 
-#include "ble/services/iBeacon.h"
+#include <BLE.h>
 
 BLE ble;
+
 const static char     DEVICE_NAME[] = "NRF52832";
-static const uint16_t uuid16_list[] = {0xabcd,0x1234};    
+static const uint16_t uuid16_list[] = {UVService::UV_SERVICE_UUID};    
 DigitalOut Led(P0_25);
 Ticker ticker;
+UVService *UVServicePtr;
 void periodicCallback(void)
 {
       
+    UVServicePtr->poll();
     if (Led == 0)
         Led = 1;
     else
         Led = 0;
-            
 }
 
 /**
@@ -81,6 +84,8 @@
     ble.gap().onDisconnection(disconnectionCallback);
     ble.gattServer().onDataWritten(onDataWrittenCallback);
     ble.gattServer().onDataRead(onDataReadCallback); 
+    uint16_t initial_value = 0;
+    UVServicePtr = new UVService(ble,initial_value);
 
     /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
@@ -92,12 +97,11 @@
 }
 int main(void)
 {
-    ticker.attach(periodicCallback, 0.1); /* Poll devices every 100ms */
-    ble.init(bleInitComplete);
-    
+    ble.init(bleInitComplete);    
     /* SpinWait for initialization to complete. This is necessary because the
      * BLE object is used in the main loop below. */
     while (!ble.hasInitialized()) { /* spin loop */ }  
+    ticker.attach(periodicCallback, 0.1); /* Poll devices every 100ms */
     while (true) {
         ble.waitForEvent(); // allows or low power operation            
     }