schneider françois
/
MAX31820
Max31820
main.cpp@0:3fb29ad2c89d, 2018-04-30 (annotated)
- Committer:
- schnf30
- Date:
- Mon Apr 30 07:57:06 2018 +0000
- Revision:
- 0:3fb29ad2c89d
Max31820
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
schnf30 | 0:3fb29ad2c89d | 1 | #include "mbed.h" |
schnf30 | 0:3fb29ad2c89d | 2 | #include "DS1820.h" |
schnf30 | 0:3fb29ad2c89d | 3 | |
schnf30 | 0:3fb29ad2c89d | 4 | Serial serial(USBTX, USBRX); |
schnf30 | 0:3fb29ad2c89d | 5 | |
schnf30 | 0:3fb29ad2c89d | 6 | int main() |
schnf30 | 0:3fb29ad2c89d | 7 | { |
schnf30 | 0:3fb29ad2c89d | 8 | DS1820 ds1820(PA_0); // substitute PA_0 with actual mbed pin name connected to the DS1820 data pin |
schnf30 | 0:3fb29ad2c89d | 9 | |
schnf30 | 0:3fb29ad2c89d | 10 | if(ds1820.begin()) { |
schnf30 | 0:3fb29ad2c89d | 11 | ds1820.setResolution(12); |
schnf30 | 0:3fb29ad2c89d | 12 | ds1820.startConversion(); |
schnf30 | 0:3fb29ad2c89d | 13 | wait(1.0); |
schnf30 | 0:3fb29ad2c89d | 14 | while(1) { |
schnf30 | 0:3fb29ad2c89d | 15 | serial.printf("temp = %3.1f\r\n", ds1820.read()); // read temperature |
schnf30 | 0:3fb29ad2c89d | 16 | ds1820.startConversion(); // start temperature conversion |
schnf30 | 0:3fb29ad2c89d | 17 | wait(1.0); // let DS1820 complete the temperature conversion |
schnf30 | 0:3fb29ad2c89d | 18 | } |
schnf30 | 0:3fb29ad2c89d | 19 | } else |
schnf30 | 0:3fb29ad2c89d | 20 | serial.printf("No DS1820 sensor found!\r\n"); |
schnf30 | 0:3fb29ad2c89d | 21 | } |