hvuhaushv;ov

Dependencies:   INA226_ver1 mbed

Fork of INA226TEST by Toshihisa T

main.cpp

Committer:
tsumagari
Date:
2017-05-27
Revision:
3:e37fd18c08e6
Parent:
2:86728e672228

File content as of revision 3:e37fd18c08e6:

/*
 * Copyright (c) 2011 Toshihisa T
 * Released under the MIT License: http://mbed.org/license/mit
 */

#include "mbed.h"
#include "INA226.hpp"

Serial debug(USBTX,USBRX);
DigitalOut myled(LED1);
I2C i2c(p9,p10);
INA226 VCmonitor(i2c,0x9C);
INA226 VCmonitor2(i2c,0x94);

int main() {
    unsigned short val;
    double V,C;
    int count = 1;

    debug.format(8,ParityNone,1);
    debug.baud(9600);
    debug.printf("VCmonitor INA226 TEST Program. (BUILD:[" __DATE__ "/" __TIME__ "])\n\r");
    
//    int flag = VCmonitor.isExist();
//    if(flag){
//        debug.printf("VCmonitor FOUND\n");
////        while(1){}
//    }else{
//        error("VCmonitor NOT FOUND\n");
//    }

    val = 0;
    if(VCmonitor.rawRead(0x00,&val) != 0){
        debug.printf("VCmonitor READ ERROR\n");
        while(1){}
    }
    debug.printf("VCmonitor Reg 0x00 : 0x%04x\n",val);

    VCmonitor.setCurrentCalibration();

    while(1) {
        if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){
            debug.printf("%d,V:%f,C:%f\n\r",count,V,C);
        }
        if((VCmonitor2.getVoltage(&V) == 0) && (VCmonitor2.getCurrent(&C) == 0)){
            debug.printf("------------%d,V:%f,C:%f\n\r",count,V,C);
        }
        myled = 1;
        wait(0.5);
        myled = 0;
        wait(0.5);
        count++;
    }
}