Simple DS1820 sensor demo showing how to use the DS1820 library [https://developer.mbed.org/users/hudakz/code/DS1820/]
main.cpp@0:77a366f9ba45, 2015-03-19 (annotated)
- Committer:
- hudakz
- Date:
- Thu Mar 19 19:25:49 2015 +0000
- Revision:
- 0:77a366f9ba45
- Child:
- 1:fe12bf2ad337
Initial revision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:77a366f9ba45 | 1 | /* |
hudakz | 0:77a366f9ba45 | 2 | * Simple DS1820 sensor demo |
hudakz | 0:77a366f9ba45 | 3 | */ |
hudakz | 0:77a366f9ba45 | 4 | |
hudakz | 0:77a366f9ba45 | 5 | #include "mbed.h" |
hudakz | 0:77a366f9ba45 | 6 | #include "DS1820.h" |
hudakz | 0:77a366f9ba45 | 7 | |
hudakz | 0:77a366f9ba45 | 8 | Serial serial(USBTX, USBRX); |
hudakz | 0:77a366f9ba45 | 9 | |
hudakz | 0:77a366f9ba45 | 10 | int main() { |
hudakz | 0:77a366f9ba45 | 11 | DS1820 ds1820(PA_9); |
hudakz | 0:77a366f9ba45 | 12 | |
hudakz | 0:77a366f9ba45 | 13 | // detect and initialize DS1820 sensor |
hudakz | 0:77a366f9ba45 | 14 | if(ds1820.begin()) { |
hudakz | 0:77a366f9ba45 | 15 | ds1820.startConversion(); // start temperature conversion |
hudakz | 0:77a366f9ba45 | 16 | wait(1.0); // wait to complete temperature conversion |
hudakz | 0:77a366f9ba45 | 17 | while(1) { |
hudakz | 0:77a366f9ba45 | 18 | serial.printf("temp = %3.1f\r\n", ds1820.read()); // read temperature |
hudakz | 0:77a366f9ba45 | 19 | ds1820.startConversion(); // start temperature conversion |
hudakz | 0:77a366f9ba45 | 20 | wait(1.0); // wait to complete temperature conversion |
hudakz | 0:77a366f9ba45 | 21 | } |
hudakz | 0:77a366f9ba45 | 22 | } else |
hudakz | 0:77a366f9ba45 | 23 | serial.printf("No DS1820 sensor found!\r\n"); |
hudakz | 0:77a366f9ba45 | 24 | } |