
Coding a little battery tester using ADC and a QAPASS 1602A screen
Diff: main.cpp
- Revision:
- 1:bec750608f0b
- Parent:
- 0:288158795e8d
--- a/main.cpp Wed Mar 21 19:33:08 2018 +0000 +++ b/main.cpp Wed Mar 21 19:50:47 2018 +0000 @@ -1,32 +1,43 @@ #include "mbed.h" +#include "TextLCD.h" AnalogIn analog_value(A0); Serial pc(USBTX, USBRX); DigitalOut led(LED1); +TextLCD LCD(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); int main() { float meas_r; float meas_v; + LCD.printf("HelloWorld"); + pc.printf("\n\rAnalogIn example\n\r"); - while(1) { + while(1) + { meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range // Display values pc.printf("measure = %f = %.0f mV\n\r", meas_r, meas_v); - + LCD.locate(0,1); + LCD.printf("Tension = %f mV", meas_v); // LED is ON is the value is below 1V - if (meas_v < 1000) { + if (meas_v < 1000) + { led = 1; // LED ON - } else { + } + else + { led = 0; // LED OFF } wait(1.0); // 1 second } + + return 0; }