
Coding a little battery tester using ADC and a QAPASS 1602A screen
main.cpp@1:bec750608f0b, 2018-03-21 (annotated)
- Committer:
- NicoK3
- Date:
- Wed Mar 21 19:50:47 2018 +0000
- Revision:
- 1:bec750608f0b
- Parent:
- 0:288158795e8d
Screen in place and code written but nothing shows;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
NicoK3 | 0:288158795e8d | 1 | #include "mbed.h" |
NicoK3 | 1:bec750608f0b | 2 | #include "TextLCD.h" |
NicoK3 | 0:288158795e8d | 3 | |
NicoK3 | 0:288158795e8d | 4 | AnalogIn analog_value(A0); |
NicoK3 | 0:288158795e8d | 5 | Serial pc(USBTX, USBRX); |
NicoK3 | 0:288158795e8d | 6 | |
NicoK3 | 0:288158795e8d | 7 | DigitalOut led(LED1); |
NicoK3 | 1:bec750608f0b | 8 | TextLCD LCD(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); |
NicoK3 | 0:288158795e8d | 9 | |
NicoK3 | 0:288158795e8d | 10 | int main() |
NicoK3 | 0:288158795e8d | 11 | { |
NicoK3 | 0:288158795e8d | 12 | float meas_r; |
NicoK3 | 0:288158795e8d | 13 | float meas_v; |
NicoK3 | 0:288158795e8d | 14 | |
NicoK3 | 1:bec750608f0b | 15 | LCD.printf("HelloWorld"); |
NicoK3 | 1:bec750608f0b | 16 | |
NicoK3 | 0:288158795e8d | 17 | pc.printf("\n\rAnalogIn example\n\r"); |
NicoK3 | 0:288158795e8d | 18 | |
NicoK3 | 1:bec750608f0b | 19 | while(1) |
NicoK3 | 1:bec750608f0b | 20 | { |
NicoK3 | 0:288158795e8d | 21 | |
NicoK3 | 0:288158795e8d | 22 | meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) |
NicoK3 | 0:288158795e8d | 23 | meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range |
NicoK3 | 0:288158795e8d | 24 | |
NicoK3 | 0:288158795e8d | 25 | // Display values |
NicoK3 | 0:288158795e8d | 26 | pc.printf("measure = %f = %.0f mV\n\r", meas_r, meas_v); |
NicoK3 | 1:bec750608f0b | 27 | LCD.locate(0,1); |
NicoK3 | 1:bec750608f0b | 28 | LCD.printf("Tension = %f mV", meas_v); |
NicoK3 | 0:288158795e8d | 29 | // LED is ON is the value is below 1V |
NicoK3 | 1:bec750608f0b | 30 | if (meas_v < 1000) |
NicoK3 | 1:bec750608f0b | 31 | { |
NicoK3 | 0:288158795e8d | 32 | led = 1; // LED ON |
NicoK3 | 1:bec750608f0b | 33 | } |
NicoK3 | 1:bec750608f0b | 34 | else |
NicoK3 | 1:bec750608f0b | 35 | { |
NicoK3 | 0:288158795e8d | 36 | led = 0; // LED OFF |
NicoK3 | 0:288158795e8d | 37 | } |
NicoK3 | 0:288158795e8d | 38 | |
NicoK3 | 0:288158795e8d | 39 | wait(1.0); // 1 second |
NicoK3 | 0:288158795e8d | 40 | } |
NicoK3 | 1:bec750608f0b | 41 | |
NicoK3 | 1:bec750608f0b | 42 | return 0; |
NicoK3 | 0:288158795e8d | 43 | } |