Charles Tritt
/
CE_T_Read
Initial version. Output needs to be converted to deg. C (from A to D count).
main.cpp@0:c1405e7fbed3, 2018-03-16 (annotated)
- Committer:
- CSTritt
- Date:
- Fri Mar 16 19:33:27 2018 +0000
- Revision:
- 0:c1405e7fbed3
Initial version. Output in counts. I plan to change this to deg. C in a later version. Working. Created as a blank project and then fixed to bring in mbed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 0:c1405e7fbed3 | 1 | /* |
CSTritt | 0:c1405e7fbed3 | 2 | Project: CE_Temp_Read |
CSTritt | 0:c1405e7fbed3 | 3 | File: main.cpp |
CSTritt | 0:c1405e7fbed3 | 4 | |
CSTritt | 0:c1405e7fbed3 | 5 | Reads from analog input, streams ASCII text to std serial using printf and |
CSTritt | 0:c1405e7fbed3 | 6 | lights onboard LED. Also demonstrates use of floating point literal suffix |
CSTritt | 0:c1405e7fbed3 | 7 | toeliminate warning and int constants for HIGH and LOW. |
CSTritt | 0:c1405e7fbed3 | 8 | |
CSTritt | 0:c1405e7fbed3 | 9 | Written by: Dr. C. S. Tritt |
CSTritt | 0:c1405e7fbed3 | 10 | Created: 3/14/18 (v. 0.9) |
CSTritt | 0:c1405e7fbed3 | 11 | |
CSTritt | 0:c1405e7fbed3 | 12 | */ |
CSTritt | 0:c1405e7fbed3 | 13 | #include "mbed.h" |
CSTritt | 0:c1405e7fbed3 | 14 | |
CSTritt | 0:c1405e7fbed3 | 15 | const int SIZE = 20; |
CSTritt | 0:c1405e7fbed3 | 16 | const float PAUSE = 0.001; |
CSTritt | 0:c1405e7fbed3 | 17 | const float INTERVAL = 0.5; |
CSTritt | 0:c1405e7fbed3 | 18 | |
CSTritt | 0:c1405e7fbed3 | 19 | AnalogIn analog_value(PB_0); // Same as A3 |
CSTritt | 0:c1405e7fbed3 | 20 | |
CSTritt | 0:c1405e7fbed3 | 21 | DigitalOut led(LED1); |
CSTritt | 0:c1405e7fbed3 | 22 | |
CSTritt | 0:c1405e7fbed3 | 23 | int main() { |
CSTritt | 0:c1405e7fbed3 | 24 | float value; // Value to be read and sent to serial port. |
CSTritt | 0:c1405e7fbed3 | 25 | |
CSTritt | 0:c1405e7fbed3 | 26 | printf("\nCE Dev Board Temperature Read\n"); |
CSTritt | 0:c1405e7fbed3 | 27 | led = 0; |
CSTritt | 0:c1405e7fbed3 | 28 | |
CSTritt | 0:c1405e7fbed3 | 29 | while(true) { |
CSTritt | 0:c1405e7fbed3 | 30 | int i = 0; |
CSTritt | 0:c1405e7fbed3 | 31 | float sum = 0.0; |
CSTritt | 0:c1405e7fbed3 | 32 | while (i < (SIZE - 1)) { |
CSTritt | 0:c1405e7fbed3 | 33 | value = analog_value.read(); // Read the analog input value (0 to 1). |
CSTritt | 0:c1405e7fbed3 | 34 | sum = sum + value; |
CSTritt | 0:c1405e7fbed3 | 35 | i++; |
CSTritt | 0:c1405e7fbed3 | 36 | wait(PAUSE); |
CSTritt | 0:c1405e7fbed3 | 37 | } |
CSTritt | 0:c1405e7fbed3 | 38 | float aveValue = sum/(float) SIZE; |
CSTritt | 0:c1405e7fbed3 | 39 | printf("Value = %f\n", aveValue); // Send value as text via serial port. |
CSTritt | 0:c1405e7fbed3 | 40 | led = !led; |
CSTritt | 0:c1405e7fbed3 | 41 | wait(INTERVAL); |
CSTritt | 0:c1405e7fbed3 | 42 | } |
CSTritt | 0:c1405e7fbed3 | 43 | } |