ADT7410 sample

Dependencies:   ADT7410 BLE_API mbed nRF51822

Fork of BLENano_SimpleTemplate_temp_170802 by Jun ADI

Files at this revision

API Documentation at this revision

Comitter:
Jun_adi
Date:
Thu Jul 13 08:00:48 2017 +0000
Parent:
5:95238da08cee
Child:
7:a1e3e531e518
Commit message:
ADT7410 BLE test

Changed in this revision

ADT7410.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADT7410.lib	Thu Jul 13 08:00:48 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/tkreyche/code/ADT7410/#e1aee50340ec
--- a/main.cpp	Sat May 20 15:29:47 2017 +0000
+++ b/main.cpp	Thu Jul 13 08:00:48 2017 +0000
@@ -32,7 +32,7 @@
 //------------------------------------------------------------ 
 #include "mbed.h"
 #include "ble/BLE.h"
-
+#include "ADT7410.h"
 
 //------------------------------------------------------------
 //Definition
@@ -42,7 +42,7 @@
 #define ADVERTISING_INTERVAL 160            //160 * 0.625[ms] = 100[ms]
 #define TICKER_TIME 200000                  //200000[us] = 200[ms]
 #define DIGITAL_OUT_PIN P0_9
-#define ANALOG_IN_PIN   P0_4
+//#define ANALOG_IN_PIN   P0_4
 
 
 //------------------------------------------------------------
@@ -50,8 +50,10 @@
 //------------------------------------------------------------ 
 BLE ble;
 DigitalOut      LED_SET(DIGITAL_OUT_PIN);
-AnalogIn        ANALOG(ANALOG_IN_PIN);
+//AnalogIn        ANALOG(ANALOG_IN_PIN);
 
+//I2C Pin setting P0_4=SDA, P0_5=SCL
+ADT7410 temp(P0_4, P0_5, 0x90, 10000);
 
 //------------------------------------------------------------
 //Service & Characteristic Setting
@@ -110,21 +112,20 @@
 //======================================================================
 //onTimeout
 //======================================================================
+
 void m_status_check_handle(void)
 {   
+/*
     uint8_t buf[2];
-
     //Read Analog port
     float s = ANALOG;
     uint16_t value = s*1024; 
     buf[0] = (value >> 8);
     buf[1] = value;
-    
-    //Send out
-    ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 2); 
+*/
+
 }
 
-
 //======================================================================
 //convert reverse UUID
 //======================================================================
@@ -182,11 +183,34 @@
     //Start Advertising
     ble.startAdvertising(); 
     
+    
+    uint8_t buf[2];
+    float tempadt;
+    
+    // reset sensor to default values
+    temp.reset();
+
+    // reduce sample rate to save power
+    temp.setConfig(ONE_SPS_MODE);   
+
+    
     //------------------------------------------------------------
     //Loop
     //------------------------------------------------------------
     while(1)
     {
+    
+        // get temperature every two seconds
+        tempadt = temp.getTemp();
+    
+        uint16_t value = tempadt;
+        buf[0] = (value >> 8);
+        buf[1] = value;
+    
+        //Send out
+        ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 2);
+        wait(0.5);
+        
         ble.waitForEvent(); 
     }
 }
\ No newline at end of file