hvuhaushv;ov

Dependencies:   INA226_ver1 mbed

Fork of INA226TEST by Toshihisa T

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Copyright (c) 2011 Toshihisa T
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005 
00006 #include "mbed.h"
00007 #include "INA226.hpp"
00008 
00009 Serial debug(USBTX,USBRX);
00010 DigitalOut myled(LED1);
00011 I2C i2c(p9,p10);
00012 INA226 VCmonitor(i2c,0x9C);
00013 INA226 VCmonitor2(i2c,0x94);
00014 
00015 int main() {
00016     unsigned short val;
00017     double V,C;
00018     int count = 1;
00019 
00020     debug.format(8,ParityNone,1);
00021     debug.baud(9600);
00022     debug.printf("VCmonitor INA226 TEST Program. (BUILD:[" __DATE__ "/" __TIME__ "])\n\r");
00023     
00024 //    int flag = VCmonitor.isExist();
00025 //    if(flag){
00026 //        debug.printf("VCmonitor FOUND\n");
00027 ////        while(1){}
00028 //    }else{
00029 //        error("VCmonitor NOT FOUND\n");
00030 //    }
00031 
00032     val = 0;
00033     if(VCmonitor.rawRead(0x00,&val) != 0){
00034         debug.printf("VCmonitor READ ERROR\n");
00035         while(1){}
00036     }
00037     debug.printf("VCmonitor Reg 0x00 : 0x%04x\n",val);
00038 
00039     VCmonitor.setCurrentCalibration();
00040 
00041     while(1) {
00042         if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){
00043             debug.printf("%d,V:%f,C:%f\n\r",count,V,C);
00044         }
00045         if((VCmonitor2.getVoltage(&V) == 0) && (VCmonitor2.getCurrent(&C) == 0)){
00046             debug.printf("------------%d,V:%f,C:%f\n\r",count,V,C);
00047         }
00048         myled = 1;
00049         wait(0.5);
00050         myled = 0;
00051         wait(0.5);
00052         count++;
00053     }
00054 }