A simple serial test program for the MAX17048 library.

Dependencies:   MAX17048 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MAX17048.h"
00003 
00004 MAX17048 gauge(p28, p27);
00005 
00006 int main()
00007 {
00008     //Try to open the MAX17048
00009     if (gauge.open()) {
00010         printf("Device detected!\n");
00011 
00012         //Load the default compensation value
00013         gauge.compensation(MAX17048::RCOMP0);
00014 
00015         while (1) {
00016             //Print the current state of charge
00017             printf("SOC = %f%%\n", (float)gauge);
00018 
00019             //Sleep for 0.5 seconds
00020             wait(0.5);
00021         }
00022     } else {
00023         error("Device not detected!\n");
00024     }
00025 }