![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
bChange
Dependencies: TextLCD
main.cpp@4:207de1651f4f, 2020-07-29 (annotated)
- Committer:
- nishimura_taku_pet
- Date:
- Wed Jul 29 01:10:07 2020 +0000
- Revision:
- 4:207de1651f4f
- Parent:
- 3:7e046dd4942c
- Child:
- 5:a0ebf165abb1
commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nishimura_taku_pet | 0:18811ba92e94 | 1 | /* mbed Microcontroller Library |
nishimura_taku_pet | 0:18811ba92e94 | 2 | * Copyright (c) 2019 ARM Limited |
nishimura_taku_pet | 0:18811ba92e94 | 3 | * SPDX-License-Identifier: Apache-2.0 |
nishimura_taku_pet | 0:18811ba92e94 | 4 | */ |
nishimura_taku_pet | 0:18811ba92e94 | 5 | |
nishimura_taku_pet | 0:18811ba92e94 | 6 | #include "mbed.h" |
nishimura_taku_pet | 0:18811ba92e94 | 7 | #include "TextLCD.h" |
nishimura_taku_pet | 4:207de1651f4f | 8 | #define MIN_V 2.0 |
nishimura_taku_pet | 4:207de1651f4f | 9 | #define MAX_V 2.67 |
nishimura_taku_pet | 0:18811ba92e94 | 10 | //0.107 |
nishimura_taku_pet | 4:207de1651f4f | 11 | I2C i2c_lcd(p28, p27); |
nishimura_taku_pet | 0:18811ba92e94 | 12 | TextLCD_I2C lcd(&i2c_lcd, (0x27 << 1), TextLCD::LCD16x2, TextLCD::HD44780); |
nishimura_taku_pet | 0:18811ba92e94 | 13 | |
nishimura_taku_pet | 0:18811ba92e94 | 14 | int b = 0; |
nishimura_taku_pet | 0:18811ba92e94 | 15 | AnalogIn battery(p15); |
nishimura_taku_pet | 1:60e68d110d01 | 16 | Serial pc(USBTX, USBRX); // USBシリアルポートのインスタンス |
nishimura_taku_pet | 4:207de1651f4f | 17 | int flag_b = 0; |
nishimura_taku_pet | 4:207de1651f4f | 18 | int flag_t = 0; |
nishimura_taku_pet | 2:dbb39def2b89 | 19 | void lcdBacklight(void const *argument); |
nishimura_taku_pet | 3:7e046dd4942c | 20 | RtosTimer bTimer(lcdBacklight, osTimerPeriodic); |
nishimura_taku_pet | 2:dbb39def2b89 | 21 | void lcdBacklight(void const *argument){ |
nishimura_taku_pet | 4:207de1651f4f | 22 | if(flag_b == 1){ |
nishimura_taku_pet | 2:dbb39def2b89 | 23 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 2:dbb39def2b89 | 24 | }else{ |
nishimura_taku_pet | 2:dbb39def2b89 | 25 | lcd.setBacklight(TextLCD::LightOff); |
nishimura_taku_pet | 2:dbb39def2b89 | 26 | } |
nishimura_taku_pet | 4:207de1651f4f | 27 | flag_b = !flag_b; |
nishimura_taku_pet | 2:dbb39def2b89 | 28 | } |
nishimura_taku_pet | 2:dbb39def2b89 | 29 | void change(){ |
nishimura_taku_pet | 2:dbb39def2b89 | 30 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 0:18811ba92e94 | 31 | while(true){ |
nishimura_taku_pet | 2:dbb39def2b89 | 32 | b = (int)((battery.read()* MAX_V - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 4:207de1651f4f | 33 | if(b < 0){//すべての機能停止 |
nishimura_taku_pet | 4:207de1651f4f | 34 | lcd.setBacklight(TextLCD::LightOff); |
nishimura_taku_pet | 4:207de1651f4f | 35 | bTimer.stop(); |
nishimura_taku_pet | 4:207de1651f4f | 36 | exit(1); |
nishimura_taku_pet | 2:dbb39def2b89 | 37 | }else if(b > 100){ |
nishimura_taku_pet | 2:dbb39def2b89 | 38 | b = 100; |
nishimura_taku_pet | 2:dbb39def2b89 | 39 | } |
nishimura_taku_pet | 0:18811ba92e94 | 40 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 41 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 2:dbb39def2b89 | 42 | if(b <= 30){ |
nishimura_taku_pet | 4:207de1651f4f | 43 | if(flag_t == 0){ |
nishimura_taku_pet | 3:7e046dd4942c | 44 | bTimer.start(500); |
nishimura_taku_pet | 4:207de1651f4f | 45 | flag_t = 1; |
nishimura_taku_pet | 2:dbb39def2b89 | 46 | } |
nishimura_taku_pet | 2:dbb39def2b89 | 47 | }else{ |
nishimura_taku_pet | 4:207de1651f4f | 48 | if(flag_t == 1){ |
nishimura_taku_pet | 3:7e046dd4942c | 49 | bTimer.stop(); |
nishimura_taku_pet | 2:dbb39def2b89 | 50 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 4:207de1651f4f | 51 | flag_t = 0; |
nishimura_taku_pet | 2:dbb39def2b89 | 52 | } |
nishimura_taku_pet | 2:dbb39def2b89 | 53 | } |
nishimura_taku_pet | 2:dbb39def2b89 | 54 | wait_us(1000000); |
nishimura_taku_pet | 0:18811ba92e94 | 55 | /*for(double i = MAX_V;i > MIN_V;i -= 0.05){ |
nishimura_taku_pet | 0:18811ba92e94 | 56 | b = (int)((i - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 0:18811ba92e94 | 57 | //printf("i = %.2f,b=%d%\r\n",i,b); |
nishimura_taku_pet | 0:18811ba92e94 | 58 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 59 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 0:18811ba92e94 | 60 | if(b <= 30){ |
nishimura_taku_pet | 0:18811ba92e94 | 61 | for(int j = 0;j*(2*b+20) < 200;j++){ |
nishimura_taku_pet | 0:18811ba92e94 | 62 | lcd.setBacklight(TextLCD::LightOff); |
nishimura_taku_pet | 0:18811ba92e94 | 63 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 64 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 0:18811ba92e94 | 65 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 66 | } |
nishimura_taku_pet | 0:18811ba92e94 | 67 | }else{ |
nishimura_taku_pet | 0:18811ba92e94 | 68 | thread_sleep_for(200); |
nishimura_taku_pet | 0:18811ba92e94 | 69 | } |
nishimura_taku_pet | 0:18811ba92e94 | 70 | }*/ |
nishimura_taku_pet | 0:18811ba92e94 | 71 | } |
nishimura_taku_pet | 0:18811ba92e94 | 72 | |
nishimura_taku_pet | 0:18811ba92e94 | 73 | |
nishimura_taku_pet | 0:18811ba92e94 | 74 | } |
nishimura_taku_pet | 0:18811ba92e94 | 75 | |
nishimura_taku_pet | 1:60e68d110d01 | 76 | /*void change(){ |
nishimura_taku_pet | 1:60e68d110d01 | 77 | |
nishimura_taku_pet | 1:60e68d110d01 | 78 | }*/ |
nishimura_taku_pet | 1:60e68d110d01 | 79 | |
nishimura_taku_pet | 0:18811ba92e94 | 80 | int main() |
nishimura_taku_pet | 0:18811ba92e94 | 81 | { |
nishimura_taku_pet | 2:dbb39def2b89 | 82 | //Thread thread(change,NULL,osPriorityNormal); |
nishimura_taku_pet | 2:dbb39def2b89 | 83 | Thread thread; |
nishimura_taku_pet | 2:dbb39def2b89 | 84 | thread.start(change); |
nishimura_taku_pet | 0:18811ba92e94 | 85 | while (true) { |
nishimura_taku_pet | 0:18811ba92e94 | 86 | wait(1); |
nishimura_taku_pet | 0:18811ba92e94 | 87 | } |
nishimura_taku_pet | 0:18811ba92e94 | 88 | } |