Coding a little battery tester using ADC and a QAPASS 1602A screen

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 AnalogIn analog_value(A0);
00005 Serial pc(USBTX, USBRX);
00006 
00007 DigitalOut led(LED1);
00008 TextLCD LCD(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0);
00009 
00010 int main()
00011 {
00012     float meas_r;
00013     float meas_v;
00014     
00015     LCD.printf("HelloWorld");
00016     
00017     pc.printf("\n\rAnalogIn example\n\r");
00018 
00019     while(1) 
00020     {
00021 
00022         meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
00023         meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
00024         
00025         // Display values
00026         pc.printf("measure = %f = %.0f mV\n\r", meas_r, meas_v);
00027         LCD.locate(0,1);
00028         LCD.printf("Tension = %f mV", meas_v);
00029         // LED is ON is the value is below 1V
00030         if (meas_v < 1000) 
00031         {
00032             led = 1; // LED ON
00033         } 
00034         else 
00035         {
00036             led = 0; // LED OFF
00037         }
00038 
00039         wait(1.0); // 1 second
00040     }
00041     
00042     return 0;
00043 }