Temperature + Digital Disapley
Dependencies: DigitDisplay mbed
Fork of Grove_Thermometer by
main.cpp@2:c62f7e612d5e, 2015-02-08 (annotated)
- Committer:
- JokerChuang
- Date:
- Sun Feb 08 08:36:11 2015 +0000
- Revision:
- 2:c62f7e612d5e
- Parent:
- 1:b4a3436b7cd0
Modify
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
djbottrill | 0:e253fc5f8e16 | 1 | /* Grove - Temprature Sensor demo v1.0 |
djbottrill | 0:e253fc5f8e16 | 2 | * This sensor detects the enviroment temprature, |
djbottrill | 0:e253fc5f8e16 | 3 | * Uses a Arch-Pro board with Grove Base Shield |
djbottrill | 0:e253fc5f8e16 | 4 | * Connect the Grove Temperature sensor to A0 and |
djbottrill | 0:e253fc5f8e16 | 5 | * connect a Grove 4 digit LED display to the UART connector |
djbottrill | 0:e253fc5f8e16 | 6 | * The temperature will be displayed in Celcius |
djbottrill | 0:e253fc5f8e16 | 7 | * Modified by David Bottrill from the original Arduino code |
JokerChuang | 2:c62f7e612d5e | 8 | * Reference: http://www.seeedstudio.com |
djbottrill | 0:e253fc5f8e16 | 9 | */ |
djbottrill | 0:e253fc5f8e16 | 10 | |
djbottrill | 0:e253fc5f8e16 | 11 | #include "mbed.h" |
djbottrill | 0:e253fc5f8e16 | 12 | #include "DigitDisplay.h" |
djbottrill | 0:e253fc5f8e16 | 13 | |
JokerChuang | 1:b4a3436b7cd0 | 14 | DigitalOut myled(LED2); |
djbottrill | 0:e253fc5f8e16 | 15 | |
djbottrill | 0:e253fc5f8e16 | 16 | DigitDisplay display(P4_29, P4_28); |
djbottrill | 0:e253fc5f8e16 | 17 | AnalogIn ain(P0_23); |
djbottrill | 0:e253fc5f8e16 | 18 | |
djbottrill | 0:e253fc5f8e16 | 19 | int a; |
djbottrill | 0:e253fc5f8e16 | 20 | float temperature; |
djbottrill | 0:e253fc5f8e16 | 21 | int B=3975; //B value of the thermistor |
djbottrill | 0:e253fc5f8e16 | 22 | float resistance; |
djbottrill | 0:e253fc5f8e16 | 23 | |
djbottrill | 0:e253fc5f8e16 | 24 | int main() |
djbottrill | 0:e253fc5f8e16 | 25 | { |
djbottrill | 0:e253fc5f8e16 | 26 | while(1) { |
djbottrill | 0:e253fc5f8e16 | 27 | // multiply ain by 675 if the Grove shield is set to 5V or 1023 if set to 3.3V |
djbottrill | 0:e253fc5f8e16 | 28 | a=ain*675; |
djbottrill | 0:e253fc5f8e16 | 29 | resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor; |
djbottrill | 0:e253fc5f8e16 | 30 | temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; //convert to temperature via datasheet ; |
djbottrill | 0:e253fc5f8e16 | 31 | myled = 1; |
JokerChuang | 2:c62f7e612d5e | 32 | wait(0.8); |
djbottrill | 0:e253fc5f8e16 | 33 | myled = 0; |
JokerChuang | 2:c62f7e612d5e | 34 | wait(0.8); |
djbottrill | 0:e253fc5f8e16 | 35 | display.write(temperature); |
djbottrill | 0:e253fc5f8e16 | 36 | } |
djbottrill | 0:e253fc5f8e16 | 37 | } |
djbottrill | 0:e253fc5f8e16 | 38 | |
djbottrill | 0:e253fc5f8e16 | 39 |