Jurica Resetar
/
acd52832_TempRead
acd52832_TempRead example
main.cpp@0:b19f4bca544a, 2016-09-20 (annotated)
- Committer:
- jurica238814
- Date:
- Tue Sep 20 12:10:53 2016 +0000
- Revision:
- 0:b19f4bca544a
acd52832_TempRead example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:b19f4bca544a | 1 | /* Copyright (c) 2016 Aconno. All Rights Reserved. |
jurica238814 | 0:b19f4bca544a | 2 | * |
jurica238814 | 0:b19f4bca544a | 3 | * Licensees are granted free, non-transferable use of the information. NO |
jurica238814 | 0:b19f4bca544a | 4 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jurica238814 | 0:b19f4bca544a | 5 | * the file. |
jurica238814 | 0:b19f4bca544a | 6 | * |
jurica238814 | 0:b19f4bca544a | 7 | */ |
jurica238814 | 0:b19f4bca544a | 8 | |
jurica238814 | 0:b19f4bca544a | 9 | #include "mbed.h" |
jurica238814 | 0:b19f4bca544a | 10 | #include "acd52832_bsp.h" |
jurica238814 | 0:b19f4bca544a | 11 | |
jurica238814 | 0:b19f4bca544a | 12 | #define V0 0.5 //In volts |
jurica238814 | 0:b19f4bca544a | 13 | #define TC 0.01 //In volts |
jurica238814 | 0:b19f4bca544a | 14 | #define VCC (3.3) |
jurica238814 | 0:b19f4bca544a | 15 | |
jurica238814 | 0:b19f4bca544a | 16 | #define RX (p25) |
jurica238814 | 0:b19f4bca544a | 17 | #define TX (p26) |
jurica238814 | 0:b19f4bca544a | 18 | |
jurica238814 | 0:b19f4bca544a | 19 | // initialize serial port |
jurica238814 | 0:b19f4bca544a | 20 | Serial pc(TX, RX); |
jurica238814 | 0:b19f4bca544a | 21 | |
jurica238814 | 0:b19f4bca544a | 22 | AnalogIn tempVoltage (ADC_TEMP); |
jurica238814 | 0:b19f4bca544a | 23 | DigitalOut Hot(PIN_LED_RED); |
jurica238814 | 0:b19f4bca544a | 24 | DigitalOut Cold(PIN_LED_BLUE); |
jurica238814 | 0:b19f4bca544a | 25 | |
jurica238814 | 0:b19f4bca544a | 26 | float getTemperature(float vout){ |
jurica238814 | 0:b19f4bca544a | 27 | return ((float)vout - (float)V0)/((float)TC); |
jurica238814 | 0:b19f4bca544a | 28 | } |
jurica238814 | 0:b19f4bca544a | 29 | |
jurica238814 | 0:b19f4bca544a | 30 | int main(){ |
jurica238814 | 0:b19f4bca544a | 31 | |
jurica238814 | 0:b19f4bca544a | 32 | // Clear LEDs |
jurica238814 | 0:b19f4bca544a | 33 | Hot = 1; |
jurica238814 | 0:b19f4bca544a | 34 | Cold = 1; |
jurica238814 | 0:b19f4bca544a | 35 | |
jurica238814 | 0:b19f4bca544a | 36 | while(1){ |
jurica238814 | 0:b19f4bca544a | 37 | pc.printf("Current temperature: %f\n", getTemperature(tempVoltage.read()*(float)VCC)); |
jurica238814 | 0:b19f4bca544a | 38 | if (getTemperature(tempVoltage.read()*(float)VCC) > 22){ |
jurica238814 | 0:b19f4bca544a | 39 | // Turn Hot ON |
jurica238814 | 0:b19f4bca544a | 40 | Hot = 0; |
jurica238814 | 0:b19f4bca544a | 41 | Cold = 1; |
jurica238814 | 0:b19f4bca544a | 42 | } |
jurica238814 | 0:b19f4bca544a | 43 | else{ |
jurica238814 | 0:b19f4bca544a | 44 | // Turn Cold On |
jurica238814 | 0:b19f4bca544a | 45 | Hot = 1; |
jurica238814 | 0:b19f4bca544a | 46 | Cold = 0; |
jurica238814 | 0:b19f4bca544a | 47 | } |
jurica238814 | 0:b19f4bca544a | 48 | wait(1); |
jurica238814 | 0:b19f4bca544a | 49 | } |
jurica238814 | 0:b19f4bca544a | 50 | } |