mingjun xu
/
DS1820_simple_test
A DS1820 temperature sensor test.
main.cpp@0:3f2965cd42bc, 2017-12-06 (annotated)
- Committer:
- mingjunxu
- Date:
- Wed Dec 06 11:29:36 2017 +0000
- Revision:
- 0:3f2965cd42bc
A simple DS1820 temperture sensor One Wire Test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mingjunxu | 0:3f2965cd42bc | 1 | #include "mbed.h" |
mingjunxu | 0:3f2965cd42bc | 2 | #include "DS1820.h" |
mingjunxu | 0:3f2965cd42bc | 3 | #define DATA_PIN D12 |
mingjunxu | 0:3f2965cd42bc | 4 | /*on the DATA_PIN (a 4.7K resistor tp VCC is necessary)*/ |
mingjunxu | 0:3f2965cd42bc | 5 | |
mingjunxu | 0:3f2965cd42bc | 6 | DS1820 probe(DATA_PIN); |
mingjunxu | 0:3f2965cd42bc | 7 | |
mingjunxu | 0:3f2965cd42bc | 8 | int main() { |
mingjunxu | 0:3f2965cd42bc | 9 | // Initialize the probe array to DS1820 objects |
mingjunxu | 0:3f2965cd42bc | 10 | DS1820::unassignedProbe(DATA_PIN); |
mingjunxu | 0:3f2965cd42bc | 11 | float celsius, fahrenheit; |
mingjunxu | 0:3f2965cd42bc | 12 | |
mingjunxu | 0:3f2965cd42bc | 13 | printf("A simple DS1820 Test:\r\n"); |
mingjunxu | 0:3f2965cd42bc | 14 | while(1) { |
mingjunxu | 0:3f2965cd42bc | 15 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
mingjunxu | 0:3f2965cd42bc | 16 | celsius = probe.temperature(); |
mingjunxu | 0:3f2965cd42bc | 17 | fahrenheit = celsius * 1.8f + 32.0f; |
mingjunxu | 0:3f2965cd42bc | 18 | printf("Temperture = %.1f celsius, %.1f fahrenheit.\r\n",celsius, fahrenheit); |
mingjunxu | 0:3f2965cd42bc | 19 | wait(1); |
mingjunxu | 0:3f2965cd42bc | 20 | } |
mingjunxu | 0:3f2965cd42bc | 21 | |
mingjunxu | 0:3f2965cd42bc | 22 | } |