Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
DS18B20_SensorTemperatura.cpp@1:0e0967c88590, 2017-03-30 (annotated)
- Committer:
- brunofgc
- Date:
- Thu Mar 30 19:54:09 2017 +0000
- Revision:
- 1:0e0967c88590
- Child:
- 2:55b7b466e742
Antes de corrigir Aloca??o Din?mica Mal feita
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| brunofgc | 1:0e0967c88590 | 1 | #include "DS18B20_SensorTemperatura.h" |
| brunofgc | 1:0e0967c88590 | 2 | |
| brunofgc | 1:0e0967c88590 | 3 | DS1820* probe[MAX_PROBES]; |
| brunofgc | 1:0e0967c88590 | 4 | int num_temperatureSensors = 0; |
| brunofgc | 1:0e0967c88590 | 5 | float temperaturas[MAX_PROBES]; |
| brunofgc | 1:0e0967c88590 | 6 | |
| brunofgc | 1:0e0967c88590 | 7 | void inicializaSensoresTemperatura(){ |
| brunofgc | 1:0e0967c88590 | 8 | // Initialize the probe array to DS1820 objects |
| brunofgc | 1:0e0967c88590 | 9 | while(DS1820::unassignedProbe(DATA_PIN)) { |
| brunofgc | 1:0e0967c88590 | 10 | probe[num_temperatureSensors] = new DS1820(DATA_PIN); |
| brunofgc | 1:0e0967c88590 | 11 | num_temperatureSensors++; |
| brunofgc | 1:0e0967c88590 | 12 | if (num_temperatureSensors == MAX_PROBES) |
| brunofgc | 1:0e0967c88590 | 13 | break; |
| brunofgc | 1:0e0967c88590 | 14 | } |
| brunofgc | 1:0e0967c88590 | 15 | printf("Found %d device(s)\r\n\n", num_temperatureSensors); |
| brunofgc | 1:0e0967c88590 | 16 | } |
| brunofgc | 1:0e0967c88590 | 17 | |
| brunofgc | 1:0e0967c88590 | 18 | void refreshSensoresTemperatura(){ |
| brunofgc | 1:0e0967c88590 | 19 | if(num_temperatureSensors){ |
| brunofgc | 1:0e0967c88590 | 20 | probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
| brunofgc | 1:0e0967c88590 | 21 | for (int i = 0; i<num_temperatureSensors; i++){ |
| brunofgc | 1:0e0967c88590 | 22 | temperaturas[i] = probe[i]->temperature(); |
| brunofgc | 1:0e0967c88590 | 23 | printf("Device %d returns %3.1foC\r\n", i, temperaturas[i]); |
| brunofgc | 1:0e0967c88590 | 24 | } |
| brunofgc | 1:0e0967c88590 | 25 | } |
| brunofgc | 1:0e0967c88590 | 26 | } |
| brunofgc | 1:0e0967c88590 | 27 | |
| brunofgc | 1:0e0967c88590 | 28 | /* |
| brunofgc | 1:0e0967c88590 | 29 | while(1) { |
| brunofgc | 1:0e0967c88590 | 30 | probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
| brunofgc | 1:0e0967c88590 | 31 | for (int i = 0; i<num_temperatureSensors; i++) |
| brunofgc | 1:0e0967c88590 | 32 | printf("Device %d returns %3.1foC\r\n", i, probe[i]->temperature()); |
| brunofgc | 1:0e0967c88590 | 33 | wait(1); |
| brunofgc | 1:0e0967c88590 | 34 | } |
| brunofgc | 1:0e0967c88590 | 35 | */ |