A simple serial test program for the MAX17048 library.

Dependencies:   MAX17048 mbed

Files at this revision

API Documentation at this revision

Comitter:
neilt6
Date:
Wed Aug 28 17:54:24 2013 +0000
Parent:
0:54ca3b1d1f75
Child:
2:fbf5cabf5658
Commit message:
Added check for device connection before testing loop

Changed in this revision

MAX17048.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
--- a/MAX17048.lib	Wed Aug 14 05:03:09 2013 +0000
+++ b/MAX17048.lib	Wed Aug 28 17:54:24 2013 +0000
@@ -1,1 +1,1 @@
-MAX17048#0a98e081b48c
+MAX17048#32087cca331f
--- a/main.cpp	Wed Aug 14 05:03:09 2013 +0000
+++ b/main.cpp	Wed Aug 28 17:54:24 2013 +0000
@@ -3,15 +3,23 @@
 
 MAX17048 gauge(p28, p27);
 
-int main() {
-    while (1) {
-        //Read the cell voltage
-        float vcell = gauge.vcell();
+int main()
+{
+    //Try to open the MAX17048
+    if (gauge.open()) {
+        printf("Device detected!\n");
 
-        //Print the cell voltage
-        printf("Vcell = %f\n", vcell);
+        while (1) {
+            //Read the cell voltage
+            float vcell = gauge.vcell();
 
-        //Sleep for 0.5 seconds
-        wait(0.5);
+            //Print the cell voltage
+            printf("Vcell = %f\n", vcell);
+
+            //Sleep for 0.5 seconds
+            wait(0.5);
+        }
+    } else {
+        printf("Device not detected!\n");
     }
 }