![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
bChange
Dependencies: TextLCD
main.cpp@1:60e68d110d01, 2020-07-27 (annotated)
- Committer:
- nishimura_taku_pet
- Date:
- Mon Jul 27 06:41:27 2020 +0000
- Revision:
- 1:60e68d110d01
- Parent:
- 0:18811ba92e94
- Child:
- 2:dbb39def2b89
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 | 1:60e68d110d01 | 16 | Serial pc(USBTX, USBRX); // USBシリアルポートのインスタンス |
nishimura_taku_pet | 1:60e68d110d01 | 17 | double test; |
nishimura_taku_pet | 1:60e68d110d01 | 18 | void change(void const *argument){ |
nishimura_taku_pet | 0:18811ba92e94 | 19 | while(true){ |
nishimura_taku_pet | 0:18811ba92e94 | 20 | //lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 1:60e68d110d01 | 21 | test = battery.read()*MAX_V; |
nishimura_taku_pet | 1:60e68d110d01 | 22 | b = (int)((test - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 1:60e68d110d01 | 23 | pc.printf("%f\r\n",test); |
nishimura_taku_pet | 0:18811ba92e94 | 24 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 25 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 0:18811ba92e94 | 26 | thread_sleep_for(200); |
nishimura_taku_pet | 0:18811ba92e94 | 27 | /*for(double i = MAX_V;i > MIN_V;i -= 0.05){ |
nishimura_taku_pet | 0:18811ba92e94 | 28 | b = (int)((i - MIN_V)/0.107 + 0.5)*10; |
nishimura_taku_pet | 0:18811ba92e94 | 29 | //printf("i = %.2f,b=%d%\r\n",i,b); |
nishimura_taku_pet | 0:18811ba92e94 | 30 | lcd.locate(0,0); |
nishimura_taku_pet | 0:18811ba92e94 | 31 | lcd.printf("Battery:%3d%%",b); |
nishimura_taku_pet | 0:18811ba92e94 | 32 | if(b <= 30){ |
nishimura_taku_pet | 0:18811ba92e94 | 33 | for(int j = 0;j*(2*b+20) < 200;j++){ |
nishimura_taku_pet | 0:18811ba92e94 | 34 | lcd.setBacklight(TextLCD::LightOff); |
nishimura_taku_pet | 0:18811ba92e94 | 35 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 36 | lcd.setBacklight(TextLCD::LightOn); |
nishimura_taku_pet | 0:18811ba92e94 | 37 | thread_sleep_for(b+10); |
nishimura_taku_pet | 0:18811ba92e94 | 38 | } |
nishimura_taku_pet | 0:18811ba92e94 | 39 | }else{ |
nishimura_taku_pet | 0:18811ba92e94 | 40 | thread_sleep_for(200); |
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 | |
nishimura_taku_pet | 0:18811ba92e94 | 46 | } |
nishimura_taku_pet | 0:18811ba92e94 | 47 | |
nishimura_taku_pet | 1:60e68d110d01 | 48 | /*void change(){ |
nishimura_taku_pet | 1:60e68d110d01 | 49 | |
nishimura_taku_pet | 1:60e68d110d01 | 50 | }*/ |
nishimura_taku_pet | 1:60e68d110d01 | 51 | |
nishimura_taku_pet | 0:18811ba92e94 | 52 | int main() |
nishimura_taku_pet | 0:18811ba92e94 | 53 | { |
nishimura_taku_pet | 1:60e68d110d01 | 54 | Thread thread(change,NULL,osPriorityNormal); |
nishimura_taku_pet | 1:60e68d110d01 | 55 | //Thread thread; |
nishimura_taku_pet | 1:60e68d110d01 | 56 | //thread.start(change); |
nishimura_taku_pet | 1:60e68d110d01 | 57 | thread.terminate(); |
nishimura_taku_pet | 1:60e68d110d01 | 58 | thread.start(mbed::Callback<void()>(change)); |
nishimura_taku_pet | 0:18811ba92e94 | 59 | |
nishimura_taku_pet | 0:18811ba92e94 | 60 | while (true) { |
nishimura_taku_pet | 0:18811ba92e94 | 61 | wait(1); |
nishimura_taku_pet | 0:18811ba92e94 | 62 | } |
nishimura_taku_pet | 0:18811ba92e94 | 63 | } |