Modified from arduino library https://github.com/pololu/vl53l0x-arduino

Dependencies:   mbed

Revision:
0:d738e3a03cf8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 16 08:45:17 2017 +0000
@@ -0,0 +1,84 @@
+#include "mbed.h"
+#include "VL53L0X_SH.h"
+
+#define Rms 5000            //TT rate
+#define dt  0.005f
+#define NN  200
+
+#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
+
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓GPIO registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+//~~~structure~~~//
+DigitalOut  led(D13);           //detection
+DigitalOut  TT_ext(D12);
+
+//~~~VL53L0X_I2C~~~//
+//I2C         i2c(D14, D15);      //I2C reg(SDA, SCL)
+VL53L0X sensor;
+//~~~Serial~~~//
+Serial      pc(D1, D0);         //Serial reg(TX RX)
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of GPIO registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Varible registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+//~~~globle~~~//
+Ticker  TT;                     //call a timer
+int     count = 0;              //one second counter for extrenal led blink
+
+//~~~VL53L0X_I2C~~~//
+int     Distance = 0;
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Varible registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Function registor↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+void    init_TIMER();           //set TT_main() rate
+void    TT_main();              //timebase function rated by TT
+void    init_IO();              //initialize IO state
+float   lpf(float input, float output_old, float frequency);    //lpf discrete
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Function registor↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓main funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+int main()
+{
+    init_IO();                  //initialized value
+    sensor.init();              //init SENSOR
+    sensor.setTimeout(500);
+    sensor.startContinuous();
+    NVIC_SetPriority(TIM5_IRQn, 51);    //!!!!!!!!!!!!!!!!!!!!!!!!!
+    init_TIMER();               //start TT_main
+
+    while(1) {                  //main() loop
+        if(count >= NN) {       //check if main working
+            count=0;
+            led = !led;
+        }
+    }
+
+}
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of main funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓Timebase funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+void init_TIMER()                   //set TT_main{} rate
+{
+    TT.attach_us(&TT_main, Rms);
+}
+void TT_main()                      //interrupt function by TT
+{
+    TT_ext = !TT_ext;               //indicate TT_main() function working
+    count = count+1;                //one second counter
+    Distance = sensor.readRangeContinuousMillimeters();
+
+//for Serial-Oscilloscope
+    pc.printf("%d\r", Distance);
+}
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of Timebase funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓init_IO funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+void init_IO(void)                  //initialize
+{
+    pc.baud(9600);            //set baud rate
+    TT_ext = 0;
+    led = 0;
+}
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of init_IO funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
+//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓lpf funtion↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
+float lpf(float input, float output_old, float frequency)
+{
+    float output = 0;
+    output = (output_old + frequency*dt*input) / (1 + frequency*dt);
+    return output;
+}
+//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑end of lpf funtion↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑//
\ No newline at end of file