Neil Thiessen
/
MAX17048_HelloWorld
A simple serial test program for the MAX17048 library.
main.cpp@9:106878f66ef0, 2014-05-30 (annotated)
- Committer:
- neilt6
- Date:
- Fri May 30 19:03:21 2014 +0000
- Revision:
- 9:106878f66ef0
- Parent:
- 6:20e76649ba57
Updated MAX17048 library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:54ca3b1d1f75 | 1 | #include "mbed.h" |
neilt6 | 0:54ca3b1d1f75 | 2 | #include "MAX17048.h" |
neilt6 | 0:54ca3b1d1f75 | 3 | |
neilt6 | 0:54ca3b1d1f75 | 4 | MAX17048 gauge(p28, p27); |
neilt6 | 0:54ca3b1d1f75 | 5 | |
neilt6 | 1:d098c4448f6d | 6 | int main() |
neilt6 | 1:d098c4448f6d | 7 | { |
neilt6 | 1:d098c4448f6d | 8 | //Try to open the MAX17048 |
neilt6 | 1:d098c4448f6d | 9 | if (gauge.open()) { |
neilt6 | 1:d098c4448f6d | 10 | printf("Device detected!\n"); |
neilt6 | 0:54ca3b1d1f75 | 11 | |
neilt6 | 6:20e76649ba57 | 12 | //Load the default compensation value |
neilt6 | 6:20e76649ba57 | 13 | gauge.compensation(MAX17048::RCOMP0); |
neilt6 | 6:20e76649ba57 | 14 | |
neilt6 | 1:d098c4448f6d | 15 | while (1) { |
neilt6 | 3:2152dd143ba3 | 16 | //Print the current state of charge |
neilt6 | 3:2152dd143ba3 | 17 | printf("SOC = %f%%\n", (float)gauge); |
neilt6 | 1:d098c4448f6d | 18 | |
neilt6 | 1:d098c4448f6d | 19 | //Sleep for 0.5 seconds |
neilt6 | 1:d098c4448f6d | 20 | wait(0.5); |
neilt6 | 1:d098c4448f6d | 21 | } |
neilt6 | 1:d098c4448f6d | 22 | } else { |
neilt6 | 3:2152dd143ba3 | 23 | error("Device not detected!\n"); |
neilt6 | 0:54ca3b1d1f75 | 24 | } |
neilt6 | 0:54ca3b1d1f75 | 25 | } |