Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:38649de1d7c1, 2020-11-18 (annotated)
- Committer:
- turko
- Date:
- Wed Nov 18 21:16:35 2020 +0000
- Revision:
- 0:38649de1d7c1
test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| turko | 0:38649de1d7c1 | 1 | #include "mbed.h" |
| turko | 0:38649de1d7c1 | 2 | |
| turko | 0:38649de1d7c1 | 3 | AnalogIn analog_value(A0); |
| turko | 0:38649de1d7c1 | 4 | |
| turko | 0:38649de1d7c1 | 5 | DigitalOut led(LED1); |
| turko | 0:38649de1d7c1 | 6 | |
| turko | 0:38649de1d7c1 | 7 | int main() |
| turko | 0:38649de1d7c1 | 8 | { |
| turko | 0:38649de1d7c1 | 9 | float meas_r; |
| turko | 0:38649de1d7c1 | 10 | float meas_v; |
| turko | 0:38649de1d7c1 | 11 | float R; |
| turko | 0:38649de1d7c1 | 12 | float T; |
| turko | 0:38649de1d7c1 | 13 | float k; |
| turko | 0:38649de1d7c1 | 14 | |
| turko | 0:38649de1d7c1 | 15 | printf("\nTest du Programme a base de potentiometre\n"); |
| turko | 0:38649de1d7c1 | 16 | |
| turko | 0:38649de1d7c1 | 17 | while(1) { |
| turko | 0:38649de1d7c1 | 18 | |
| turko | 0:38649de1d7c1 | 19 | k = analog_value.read(); |
| turko | 0:38649de1d7c1 | 20 | meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) |
| turko | 0:38649de1d7c1 | 21 | meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range |
| turko | 0:38649de1d7c1 | 22 | |
| turko | 0:38649de1d7c1 | 23 | R = (11000)/((1/meas_r)-1); |
| turko | 0:38649de1d7c1 | 24 | T=(1/((1/298.15)+ (log10(R/10000))/3973))-273.15; |
| turko | 0:38649de1d7c1 | 25 | |
| turko | 0:38649de1d7c1 | 26 | |
| turko | 0:38649de1d7c1 | 27 | |
| turko | 0:38649de1d7c1 | 28 | // Display values |
| turko | 0:38649de1d7c1 | 29 | printf("\nmeasure = %f = %.0f C\n", meas_r, meas_v); |
| turko | 0:38649de1d7c1 | 30 | printf("\ntest %f , %f, %f\n",R,T,k); |
| turko | 0:38649de1d7c1 | 31 | printf("measure temperature = %f C",T); |
| turko | 0:38649de1d7c1 | 32 | |
| turko | 0:38649de1d7c1 | 33 | // LED is ON is the value is below 1V |
| turko | 0:38649de1d7c1 | 34 | if (meas_v < 3300/2) { |
| turko | 0:38649de1d7c1 | 35 | led = 1; // LED ON |
| turko | 0:38649de1d7c1 | 36 | } else { |
| turko | 0:38649de1d7c1 | 37 | led = 0; // LED OFF |
| turko | 0:38649de1d7c1 | 38 | } |
| turko | 0:38649de1d7c1 | 39 | |
| turko | 0:38649de1d7c1 | 40 | wait(3.0); // 1 second |
| turko | 0:38649de1d7c1 | 41 | } |
| turko | 0:38649de1d7c1 | 42 | } |