Berhasil

Dependencies:   mbed ADS1115

Files at this revision

API Documentation at this revision

Comitter:
adavidkhowantolim
Date:
Mon Feb 25 15:51:38 2019 +0000
Commit message:
Berhasil;

Changed in this revision

ADS1015.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 21a035379c92 ADS1015.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADS1015.lib	Mon Feb 25 15:51:38 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/adavidkhowantolim/code/ADS1115/#441bc773778a
diff -r 000000000000 -r 21a035379c92 Main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Mon Feb 25 15:51:38 2019 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+#include "Adafruit_ADS1015.h"
+
+#define SERIAL_BAUD_RATE    9600
+
+#define a_samping       500000
+#define b_samping       1.184
+//#define b_samping       1.229
+#define a_depan         10000000
+#define b_depan         1.297
+
+I2C i2c(D14, D15);
+Adafruit_ADS1015 ads(&i2c);
+Serial pc(USBTX, USBRX);
+
+float dist = 0;
+
+float call_samping(uint16_t x) {
+  float side_distance = a_samping/pow(x,b_samping)+1;
+    return side_distance;
+}
+
+float call_depan(uint16_t x){
+    float front_distance = a_depan/pow(x,b_depan);
+    return front_distance;
+}
+
+int main() {
+    uint16_t ir;
+    const uint16_t u16tmax = 0xFFFF;
+    while (1) {
+        ir = ads.readADC_SingleEnded(2);
+        float voltage = ir * 6.2676 * 10e-5;
+        uint16_t x = voltage/3.3 * 0xFFFF ;
+        float dist = call_samping(x);
+//        pc.printf("raw = %ul volt = %.2f x=%ul dist=%.2f \n", ir, voltage, x, dist);
+        pc.printf("%.5f     %.5f\n", voltage,dist);
+        wait(0.08); // loop 2 sek
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 21a035379c92 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 25 15:51:38 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file