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.
Fork of TextLCD_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 I2CSlave i2cslave(dp5, dp27); 00005 00006 DigitalOut led1(dp14); 00007 00008 TextLCD lcd(dp17, dp18, dp25, dp10, dp26, dp28, TextLCD::LCD20x4); // rs, e, d4-d7 00009 00010 Serial pc(dp16, dp15); 00011 00012 int main() { 00013 char str[20], serBuff[64]; 00014 float SystemVoltage, AverageCellVoltage, MaxCellVoltage, MinimumCellVoltage, 00015 SystemCurrent, Motor1Current, Motor2Current, Motor3Current, 00016 Remain, PowerConsumption, IntegralPowerConsumption, IntegralCurrent; 00017 00018 int measCurrent, currentCmd, accelVol, pwmDuty, mtrRpm; 00019 00020 int MaxCellNumber, MinimumCellNumber; 00021 int32_t cellvol[12], mincell, maxcell; 00022 float realcellvol; /* real number of cell voltage */ 00023 00024 char rbuf[8]; 00025 char i2cbuf[32] = {0}; 00026 char *endPtr; 00027 00028 SystemVoltage = 120.5; //%4.1f システム電圧 00029 AverageCellVoltage = 3.123; //%4.3f 平均セル電圧 00030 MaxCellVoltage = 1.234; //%4.3f 00031 MinimumCellVoltage = 0.123; //%4.3f 00032 MaxCellNumber = 5; //%1d 00033 MinimumCellNumber = 3; //%1d 00034 SystemCurrent = 138.1235; //%3.0f 00035 Motor1Current = 11.1245; //%3.0f 00036 Motor2Current = 22.1245; //%3.0f 00037 Motor3Current = 33.1245; //%3.0f 00038 Remain = 85.435; //%3.0f 00039 PowerConsumption = 12.54; //%4.2f 00040 IntegralPowerConsumption = 1.54; //%3.2f 00041 IntegralCurrent = 43.21; //%4.2f 00042 00043 pc.baud(38400); 00044 00045 lcd.cls(); 00046 led1 = 0; 00047 lcd.locate( 0, 0); 00048 lcd.printf("rcv start"); 00049 wait(0.5); 00050 led1 = 1; 00051 00052 00053 00054 while(1){ 00055 //--------------------------------------------- 00056 // 文字列受信=>数値変換 00057 //--------------------------------------------- 00058 led1 = !led1; 00059 pc.scanf("%s", serBuff); 00060 if( 's' == serBuff[0] ){ 00061 // 文字列解釈 00062 //電流計測値(AD10bit生データ) 00063 strncpy( rbuf, &serBuff[1], 4 ); 00064 measCurrent = ( strtol( rbuf, &endPtr, 10) ); 00065 memset( rbuf, '\0', sizeof rbuf ); 00066 //電流指令値(倍率が正しくないと思う) 00067 strncpy( rbuf, &serBuff[5], 4 ); 00068 currentCmd = ( strtol( rbuf, &endPtr, 10) ); 00069 memset( rbuf, '\0', sizeof rbuf ); 00070 //ボリューム(AD10bit生データ) 00071 strncpy( rbuf, &serBuff[9], 4 ); 00072 accelVol = ( strtol( rbuf, &endPtr, 10) ); 00073 memset( rbuf, '\0', sizeof rbuf ); 00074 //PWMデューティ(0~800:MAX800) 00075 strncpy( rbuf, &serBuff[13], 4 ); 00076 pwmDuty = ( strtol( rbuf, &endPtr, 10) ); 00077 memset( rbuf, '\0', sizeof rbuf ); 00078 //モータ回転数(RPM) 00079 strncpy( rbuf, &serBuff[17], 6 ); 00080 mtrRpm = ( strtol( rbuf, &endPtr, 10) ); 00081 memset( rbuf, '\0', sizeof rbuf ); 00082 // 数値表示 00083 lcd.cls(); //<=表示クリア 00084 lcd.locate( 0, 0); //<= locate(列,行) 00085 lcd.printf("SC =%04dA", measCurrent ); 00086 lcd.locate( 0, 1); 00087 lcd.printf("cmd =%04dA", ((measCurrent - currentCmd) / 4) ); 00088 lcd.locate( 0, 2); 00089 lcd.printf("vol =%04d", accelVol ); 00090 lcd.locate( 0, 3); 00091 lcd.printf("duty=%04.1f%", ((float)(pwmDuty))/8 ); 00092 lcd.locate( 10, 0); 00093 lcd.printf("%06drpm", mtrRpm ); 00094 } 00095 // wait(0.1); 00096 00097 } 00098 }
Generated on Tue Jul 26 2022 01:35:19 by
1.7.2
