![](/media/cache/profiles/23d2018fbeae92114a4f4ff189549215.jpg.50x50_q85.png)
Auto search for All DS18B20 sensors on data bus
main.cpp@0:a2a81f538133, 2014-04-13 (annotated)
- Committer:
- umairaftab
- Date:
- Sun Apr 13 10:06:52 2014 +0000
- Revision:
- 0:a2a81f538133
Multiple Sensors Functionality Added to Peter Sudensikis Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umairaftab | 0:a2a81f538133 | 1 | #include <mbed.h> |
umairaftab | 0:a2a81f538133 | 2 | #include "DS18B20.h" |
umairaftab | 0:a2a81f538133 | 3 | #include "OneWireDefs.h" |
umairaftab | 0:a2a81f538133 | 4 | |
umairaftab | 0:a2a81f538133 | 5 | #define THERMOMETER DS18B20 |
umairaftab | 0:a2a81f538133 | 6 | |
umairaftab | 0:a2a81f538133 | 7 | float temp; |
umairaftab | 0:a2a81f538133 | 8 | // device( mbed pin ) |
umairaftab | 0:a2a81f538133 | 9 | THERMOMETER device(PTC11); |
umairaftab | 0:a2a81f538133 | 10 | |
umairaftab | 0:a2a81f538133 | 11 | void readTemp(int deviceNum) |
umairaftab | 0:a2a81f538133 | 12 | { |
umairaftab | 0:a2a81f538133 | 13 | temp = device.readTemperature(deviceNum); |
umairaftab | 0:a2a81f538133 | 14 | printf("Device %d is %f\n\r",deviceNum, temp); |
umairaftab | 0:a2a81f538133 | 15 | wait(0.5); |
umairaftab | 0:a2a81f538133 | 16 | } |
umairaftab | 0:a2a81f538133 | 17 | |
umairaftab | 0:a2a81f538133 | 18 | int main() |
umairaftab | 0:a2a81f538133 | 19 | { |
umairaftab | 0:a2a81f538133 | 20 | |
umairaftab | 0:a2a81f538133 | 21 | while (!device.initialize()); // keep calling until it works |
umairaftab | 0:a2a81f538133 | 22 | |
umairaftab | 0:a2a81f538133 | 23 | int deviceCount = device.getDeviceCount(); |
umairaftab | 0:a2a81f538133 | 24 | printf("Found %d sensors\n\r",deviceCount); |
umairaftab | 0:a2a81f538133 | 25 | |
umairaftab | 0:a2a81f538133 | 26 | device.setResolution(twelveBit); |
umairaftab | 0:a2a81f538133 | 27 | while (true) |
umairaftab | 0:a2a81f538133 | 28 | { |
umairaftab | 0:a2a81f538133 | 29 | for (int i = 0;i < deviceCount; i++) |
umairaftab | 0:a2a81f538133 | 30 | readTemp(i); |
umairaftab | 0:a2a81f538133 | 31 | } |
umairaftab | 0:a2a81f538133 | 32 | } |
umairaftab | 0:a2a81f538133 | 33 |