Hey Community
I tried to use the given example code of Dallas Temperature / Multiple for an own project.
I got the error: Exitstatus 1; variable or field ‘printAddress’ declared void. The line:
void printAddress(DeviceAddress deviceAddress) {
Is marked.
So I tried to debug it and run into something I can´t deal with.
When I copy the code in one Tab and Verify it, everything is fine. If I put the (unmodified!) code into two tabs, it depends where I put the cut. Sometimes I get the error. Espacially If I don´t expect it.
This one leads to an error.
Tab A_Dallas:
/*
Rui Santos
Complete Project Details https://randomnerdtutorials.com
*/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 4 on the Arduino
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
void setup(void)
Tab: A_Setup
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// Grab a count of devices on the wire
numberOfDevices = sensors.getDeviceCount();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(numberOfDevices, DEC);
Serial.println(" devices.");
// Loop through each device, print out address
for (int i = 0; i < numberOfDevices; i++) {
// Search the wire for address
if (sensors.getAddress(tempDeviceAddress, i)) {
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: ");
printAddress(tempDeviceAddress);
Serial.println();
} else {
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address. Check power and cabling");
}
}
}
void loop(void) {
sensors.requestTemperatures(); // Send the command to get temperatures
// Loop through each device, print out temperature data
for (int i = 0; i < numberOfDevices; i++) {
// Search the wire for address
if (sensors.getAddress(tempDeviceAddress, i)) {
// Output the device ID
Serial.print("Temperature for device: ");
Serial.println(i, DEC);
// Print the data
float tempC = sensors.getTempC(tempDeviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}
}
delay(5000);
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress) {
for (uint8_t i = 0; i < 8; i++) {
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
And the same error occours when the last line
void Setup (void)
is moved to the second tab which is the intention of tabbing the sourcecode.
But If I pull only the first line in fact one char, the “{” from the second tab to the end of the first tab, everything is fine, and there is no error.
This is not what I expect, and I don´t understand the pattern behind it. Of Course my project is somehow different but it condenses to that occurance.
I use the 1.8.13 IDE on windows 10.
Someone can give me a hint? I could not find one by myself.
thanks
Kurt