Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:588c7482a670
- Parent:
- 0:b20f8673a7fa
--- a/main.cpp Sat Nov 24 18:38:51 2012 +0000
+++ b/main.cpp Fri Apr 24 07:11:45 2020 +0000
@@ -1,48 +1,43 @@
-/*
- * Copyright (c) 2011 Toshihisa T
- * Released under the MIT License: http://mbed.org/license/mit
- */
+#include "mbed.h" // studio.hに相当
+#include "INA226.hpp" //ina226内の内部処理
-#include "mbed.h"
-#include "INA226.hpp"
+DigitalOut myled(LED1);//mbed内のLEDの点灯(動作確認用)無くてもいい
+I2C i2c(p28,p27); //I2Cで通信するためのポート設定
+INA226 VCmonitor(i2c); //ina226の測定等の関数
-Serial debug(USBTX,USBRX);
-DigitalOut myled(LED1);
-I2C i2c(p28,p27);
-INA226 VCmonitor(i2c);
+int main() { //マイコン起動時に始めにコールさせる
+ unsigned short val; //通信確認時にエラーがないか確認するための変数
+ double V,C; //この変数に電圧電流が入ってる V:電圧 C:電流
+ int count = 1; // 測定毎にカウントされる変数
+//ここから先無くてもいい
+ printf("VCmonitor INA226 TEST Program. (BUILD:[" __DATE__ "/" __TIME__ "])\n");
-int main() {
- unsigned short val;
- double V,C;
- int count = 1;
-
- debug.format(8,ParityNone,1);
- debug.baud(115200);
- debug.printf("VCmonitor INA226 TEST Program. (BUILD:[" __DATE__ "/" __TIME__ "])\n");
-
- if(!VCmonitor.isExist()){
- debug.printf("VCmonitor NOT FOUND\n");
+ if(!VCmonitor.isExist()){//通信エラー確認
+ printf("VCmonitor NOT FOUND\n");//エラーがあるとこのwhile内から抜けない
while(1){}
}
- debug.printf("VCmonitor FOUND\n");
+
+ printf("VCmonitor FOUND\n");
- val = 0;
- if(VCmonitor.rawRead(0x00,&val) != 0){
- debug.printf("VCmonitor READ ERROR\n");
+ val = 0;//初期値
+
+ if(VCmonitor.rawRead(0x00,&val) != 0){//通信確認時にエラーがないか確認するための変数
+ printf("VCmonitor READ ERROR\n");//エラーがあるとwhileから抜けない
while(1){}
}
- debug.printf("VCmonitor Reg 0x00 : 0x%04x\n",val);
+ printf("VCmonitor Reg 0x00 : 0x%04x\n",val);
+//ここより上はあっても無くてもいい
VCmonitor.setCurrentCalibration();
-
- while(1) {
+
+ while(1) { //測定開始
if((VCmonitor.getVoltage(&V) == 0) && (VCmonitor.getCurrent(&C) == 0)){
- debug.printf("%d,V,%f,C,%f\n",count,V,C);
+ printf("%d,V,%f,C,%f\n",count,V,C); //電圧、電流、カウント回数の表示
}
- myled = 1;
- wait(0.5);
- myled = 0;
- wait(0.5);
- count++;
+ myled = 1; //LED点灯
+ wait(0.5); //0.5秒待ち
+ myled = 0; //LED消灯
+ wait(0.5); //0.5秒待ち
+ count++; //一回カウント
}
-}
+}
\ No newline at end of file