![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
bChange
Dependencies: TextLCD
Diff: main.cpp
- Revision:
- 4:207de1651f4f
- Parent:
- 3:7e046dd4942c
- Child:
- 5:a0ebf165abb1
--- a/main.cpp Tue Jul 28 03:11:02 2020 +0000 +++ b/main.cpp Wed Jul 29 01:10:07 2020 +0000 @@ -5,48 +5,50 @@ #include "mbed.h" #include "TextLCD.h" -#define MIN_V 2.23 -#define MAX_V 3.3 +#define MIN_V 2.0 +#define MAX_V 2.67 //0.107 -I2C i2c_lcd(p9, p10); +I2C i2c_lcd(p28, p27); TextLCD_I2C lcd(&i2c_lcd, (0x27 << 1), TextLCD::LCD16x2, TextLCD::HD44780); int b = 0; AnalogIn battery(p15); Serial pc(USBTX, USBRX); // USBシリアルポートのインスタンス -int isBacklight = 0; -int isTimer = 0; +int flag_b = 0; +int flag_t = 0; void lcdBacklight(void const *argument); RtosTimer bTimer(lcdBacklight, osTimerPeriodic); void lcdBacklight(void const *argument){ - if(isBacklight){ + if(flag_b == 1){ lcd.setBacklight(TextLCD::LightOn); }else{ lcd.setBacklight(TextLCD::LightOff); } - isBacklight = !isBacklight; + flag_b = !flag_b; } void change(){ lcd.setBacklight(TextLCD::LightOn); while(true){ b = (int)((battery.read()* MAX_V - MIN_V)/0.107 + 0.5)*10; - if(b < 0){ - b = 0; + if(b < 0){//すべての機能停止 + lcd.setBacklight(TextLCD::LightOff); + bTimer.stop(); + exit(1); }else if(b > 100){ b = 100; } lcd.locate(0,0); lcd.printf("Battery:%3d%%",b); if(b <= 30){ - if(isTimer == 0){ - isTimer = 1; + if(flag_t == 0){ bTimer.start(500); + flag_t = 1; } }else{ - if(isTimer == 1){ + if(flag_t == 1){ bTimer.stop(); lcd.setBacklight(TextLCD::LightOn); - isTimer = 0; + flag_t = 0; } } wait_us(1000000); @@ -80,7 +82,6 @@ //Thread thread(change,NULL,osPriorityNormal); Thread thread; thread.start(change); - while (true) { wait(1); }