Hello world for the INA219 current sensing breakout form Adafruit

Dependencies:   INA219 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "INA219.hpp"
00003 
00004 Serial pc(USBTX, USBRX);
00005 DigitalOut led1(p25);
00006 
00007 // Get this to work with the INA219 Breakout from Adafruit
00008 INA219 ina219(p28, p27, 0x40, 400000, RES_10BITS);
00009 
00010 Ticker measure;
00011 float refresh_rate = 1000;
00012 
00013 void show_current()
00014 {
00015     float current_ma = ina219.read_current_mA();
00016     pc.printf("%f\r\n", current_ma);
00017     
00018     led1 = !led1;
00019 }
00020 
00021 int main(void)
00022 {
00023     pc.baud(921600);
00024 
00025     float refresh_interval = 1/refresh_rate;
00026     measure.attach(&show_current, refresh_interval);
00027 
00028     while (1) {
00029     }
00030 }