![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
bChange
Dependencies: TextLCD
main.cpp@0:18811ba92e94, 2020-07-27 (annotated)
- Committer:
- nishimura_taku_pet
- Date:
- Mon Jul 27 05:07:14 2020 +0000
- Revision:
- 0:18811ba92e94
- Child:
- 1:60e68d110d01
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 | 0:18811ba92e94 | 8 | #define MIN_V 2.23 |
nishimura_taku_pet | 0:18811ba92e94 | 9 | #define MAX_V 3.3 |
nishimura_taku_pet | 0:18811ba92e94 | 10 | //0.107 |
nishimura_taku_pet | 0:18811ba92e94 | 11 | I2C i2c_lcd(p9, p10); |
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 | 0:18811ba92e94 | 16 | |
nishimura_taku_pet | 0:18811ba92e94 | 17 | void change(){ |
nishimura_taku_pet | 0:18811ba92e94 | 18 | while(true){ |
nishimura_taku_pet | 0:18811ba92e94 | 19 | //lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 0:18811ba92e94 | 20 | b = (int)((i - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 0:18811ba92e94 | 21 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 22 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 0:18811ba92e94 | 23 | thread_sleep_for(200); |
nishimura_taku_pet | 0:18811ba92e94 | 24 | /*for(double i = MAX_V;i > MIN_V;i -= 0.05){ |
nishimura_taku_pet | 0:18811ba92e94 | 25 | b = (int)((i - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 0:18811ba92e94 | 26 | //printf("i = %.2f,b=%d%\r\n",i,b); |
nishimura_taku_pet | 0:18811ba92e94 | 27 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 28 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 0:18811ba92e94 | 29 | if(b <= 30){ |
nishimura_taku_pet | 0:18811ba92e94 | 30 | for(int j = 0;j*(2*b+20) < 200;j++){ |
nishimura_taku_pet | 0:18811ba92e94 | 31 | lcd.setBacklight(TextLCD::LightOff); |
nishimura_taku_pet | 0:18811ba92e94 | 32 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 33 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 0:18811ba92e94 | 34 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 35 | } |
nishimura_taku_pet | 0:18811ba92e94 | 36 | }else{ |
nishimura_taku_pet | 0:18811ba92e94 | 37 | thread_sleep_for(200); |
nishimura_taku_pet | 0:18811ba92e94 | 38 | } |
nishimura_taku_pet | 0:18811ba92e94 | 39 | }*/ |
nishimura_taku_pet | 0:18811ba92e94 | 40 | } |
nishimura_taku_pet | 0:18811ba92e94 | 41 | |
nishimura_taku_pet | 0:18811ba92e94 | 42 | |
nishimura_taku_pet | 0:18811ba92e94 | 43 | } |
nishimura_taku_pet | 0:18811ba92e94 | 44 | |
nishimura_taku_pet | 0:18811ba92e94 | 45 | int main() |
nishimura_taku_pet | 0:18811ba92e94 | 46 | { |
nishimura_taku_pet | 0:18811ba92e94 | 47 | //Thread thread(change,NULL,osPriorityNormal); |
nishimura_taku_pet | 0:18811ba92e94 | 48 | Thread thread; |
nishimura_taku_pet | 0:18811ba92e94 | 49 | thread.start(change); |
nishimura_taku_pet | 0:18811ba92e94 | 50 | |
nishimura_taku_pet | 0:18811ba92e94 | 51 | while (true) { |
nishimura_taku_pet | 0:18811ba92e94 | 52 | wait(1); |
nishimura_taku_pet | 0:18811ba92e94 | 53 | } |
nishimura_taku_pet | 0:18811ba92e94 | 54 | } |