bChange

Dependencies:   TextLCD

main.cpp

Committer:
nishimura_taku_pet
Date:
2020-07-27
Revision:
1:60e68d110d01
Parent:
0:18811ba92e94
Child:
2:dbb39def2b89

File content as of revision 1:60e68d110d01:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"
#include "TextLCD.h"
#define MIN_V 2.23
#define MAX_V 3.3
//0.107
I2C i2c_lcd(p9, p10);
TextLCD_I2C lcd(&i2c_lcd, (0x27 << 1), TextLCD::LCD16x2, TextLCD::HD44780);

int b = 0;
AnalogIn battery(p15);
Serial pc(USBTX, USBRX); // USBシリアルポートのインスタンス
double test;
void change(void const *argument){
        while(true){
            //lcd.setBacklight(TextLCD::LightOn);
            test = battery.read()*MAX_V;
            b = (int)((test - MIN_V)/0.107 + 0.5)*10;
            pc.printf("%f\r\n",test);
            lcd.locate(0,0);
            lcd.printf("Battery:%3d%%",b);
            thread_sleep_for(200);
            /*for(double i = MAX_V;i > MIN_V;i -= 0.05){
                b = (int)((i - MIN_V)/0.107 + 0.5)*10;
                //printf("i = %.2f,b=%d%\r\n",i,b);
                lcd.locate(0,0);
                lcd.printf("Battery:%3d%%",b);
                if(b <= 30){
                    for(int j = 0;j*(2*b+20) < 200;j++){
                        lcd.setBacklight(TextLCD::LightOff);
                        thread_sleep_for(b+10);
                        lcd.setBacklight(TextLCD::LightOn);
                        thread_sleep_for(b+10);
                    }
                }else{
                    thread_sleep_for(200);
                }
            }*/
        }
        

}

/*void change(){
    
}*/

int main()
{
    Thread thread(change,NULL,osPriorityNormal);
    //Thread thread;
    //thread.start(change);
    thread.terminate();
    thread.start(mbed::Callback<void()>(change));

    while (true) {
        wait(1);
    }
}