Is there a possibility to set the resolution, request temp, set alarm, etc... of all seven ds18b20 temp sensors (see code) by means of a for.... loop? I know there is already some kind of an array with all the sensors with an index assigned to them but I don't know how to use it.....?
I just started with programming so if somebody can point me already in a good direction...
Thanks in advance
//Included libraries
#include <OneWire.h>
#include <DallasTemperature.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
// Global variables /
////////////////////////////////////////////////////////////////////////////////////////////////////
byte alarmStatus, sensorStatus, resolutiontest;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Data wire for temp sensors is plugged into pin 3 on the Arduino /
////////////////////////////////////////////////////////////////////////////////////////////////////
#define ONE_WIRE_BUS 3
////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup a oneWire instance to communicate with any OneWire devices /
////////////////////////////////////////////////////////////////////////////////////////////////////
OneWire oneWire(ONE_WIRE_BUS);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Pass the oneWire references to Dallas Temperature library /
////////////////////////////////////////////////////////////////////////////////////////////////////
DallasTemperature sensors(&oneWire);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Manually assign sensor addresses /
////////////////////////////////////////////////////////////////////////////////////////////////////
DeviceAddress sensorINL1 = { 0x28, 0xC4, 0xEF, 0xC2, 0x03, 0x00, 0x00, 0x32 };
DeviceAddress sensorINL2 = { 0x28, 0xAC, 0xF5, 0xC2, 0x03, 0x00, 0x00, 0x91 };
DeviceAddress sensorINL3 = { 0x28, 0xC1, 0x02, 0xC3, 0x03, 0x00, 0x00, 0x60 };
DeviceAddress sensorOUTL1 = { 0x28, 0xC1, 0x19, 0xC3, 0x03, 0x00, 0x00, 0x6C };
DeviceAddress sensorOUTL2 = { 0x28, 0x61, 0xE7, 0xC2, 0x03, 0x00, 0x00, 0xBB };
DeviceAddress sensorOUTL3 = { 0x28, 0x79, 0x0A, 0xC3, 0x03, 0x00, 0x00, 0xF8 };
DeviceAddress sensorAmbient = { 0x28, 0xAD, 0x04, 0xC3, 0x03, 0x00, 0x00, 0x42 };
////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup /
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup(void){
Serial.begin(9600);// start serial port
sensors.begin();// Start up library
setResol(11);// Set resolution (12bit)
setAlarm(25);// Set alarm setpoint in °C (int, no float)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Loop /
/////////////////////////////////////////////////////////////////////////////////////////////////////
void loop(void){
delay(750);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
getTemperature(sensorINL1);
Serial.print("\n\r");
getTemperature(sensorINL2);
Serial.print("\n\r");
getTemperature(sensorINL3);
Serial.print("\n\r\n\r");
getTemperature(sensorOUTL1);
Serial.print("\n\r");
getTemperature(sensorOUTL2);
Serial.print("\n\r");
getTemperature(sensorOUTL3);
Serial.print("\n\r\n\r");
getTemperature(sensorAmbient);
Serial.print("\n\r\n\r");
checkAlarm(sensorAmbient);
sensorStatusWord;
Serial.print(sensorStatus);
Serial.print("\n\r");
}...............................................etc