1
- //
2
- // FILE: readPowerSupply.ino
3
1
// AUTHOR: Rob Tillaart
4
- // VERSION: 0.1 .0
2
+ // VERSION: 0.2 .0
5
3
// PURPOSE: demo
6
- // DATE: 2020-02-10
4
+ // DATE: 2025-01-04
7
5
//
8
6
// Released to the public domain
9
7
//
19
17
OneWire oneWire (ONE_WIRE_BUS);
20
18
21
19
// Pass our oneWire reference to Dallas Temperature.
22
- DallasTemperature sensors (&oneWire);
20
+ Dallas::DallasTemperature sensors (&oneWire);
21
+
22
+ // Arrays to hold device addresses
23
+ Dallas::DeviceAddress insideThermometer, outsideThermometer;
23
24
24
- // arrays to hold device addresses
25
- DeviceAddress insideThermometer, outsideThermometer;
26
- // Assign address manually. The addresses below will beed to be changed
25
+ // Assign address manually. The addresses below will need to be changed
27
26
// to valid device addresses on your bus. Device address can be retrieved
28
27
// by using either oneWire.search(deviceAddress) or individually via
29
28
// sensors.getAddress(deviceAddress, index)
30
- // DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
31
- // DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
29
+ // Example:
30
+ // Dallas::DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
31
+ // Dallas::DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
32
32
33
33
int devCount = 0 ;
34
34
35
35
/*
36
36
* The setup function. We only start the sensors here
37
37
*/
38
- void setup (void )
39
- {
38
+ void setup (void ) {
40
39
Serial.begin (115200 );
41
40
Serial.println (" Arduino Temperature Control Library Demo - readPowerSupply" );
42
41
@@ -46,47 +45,40 @@ void setup(void)
46
45
Serial.print (" #devices: " );
47
46
Serial.println (devCount);
48
47
49
- // report parasite power requirements
48
+ // Report parasite power requirements
50
49
Serial.print (" Parasite power is: " );
51
- if (sensors.readPowerSupply ()) Serial.println (" ON" ); // no address means "scan all devices for parasite mode"
50
+ if (sensors.isParasitePowerMode ()) Serial.println (" ON" ); // Check parasite mode globally
52
51
else Serial.println (" OFF" );
53
52
54
- // Search for devices on the bus and assign based on an index.
53
+ // Search for devices on the bus and assign based on an index
55
54
if (!sensors.getAddress (insideThermometer, 0 )) Serial.println (" Unable to find address for Device 0" );
56
55
if (!sensors.getAddress (outsideThermometer, 1 )) Serial.println (" Unable to find address for Device 1" );
57
56
58
- // show the addresses we found on the bus
57
+ // Show the addresses we found on the bus
59
58
Serial.print (" Device 0 Address: " );
60
59
printAddress (insideThermometer);
61
60
Serial.println ();
62
61
Serial.print (" Power = parasite: " );
63
62
Serial.println (sensors.readPowerSupply (insideThermometer));
64
63
Serial.println ();
65
- Serial.println ();
66
64
67
65
Serial.print (" Device 1 Address: " );
68
66
printAddress (outsideThermometer);
69
67
Serial.println ();
70
68
Serial.print (" Power = parasite: " );
71
69
Serial.println (sensors.readPowerSupply (outsideThermometer));
72
70
Serial.println ();
73
- Serial.println ();
74
71
}
75
72
76
- // function to print a device address
77
- void printAddress (DeviceAddress deviceAddress)
78
- {
79
- for (uint8_t i = 0 ; i < 8 ; i++)
80
- {
81
- // zero pad the address if necessary
73
+ // Function to print a device address
74
+ void printAddress (Dallas::DeviceAddress deviceAddress) {
75
+ for (uint8_t i = 0 ; i < 8 ; i++) {
76
+ // Zero pad the address if necessary
82
77
if (deviceAddress[i] < 0x10 ) Serial.print (" 0" );
83
78
Serial.print (deviceAddress[i], HEX);
84
79
}
85
80
}
86
81
87
- // empty on purpose
88
- void loop (void )
89
- {
82
+ // Empty on purpose
83
+ void loop (void ) {
90
84
}
91
-
92
- // END OF FILE
0 commit comments