// Incluez les bibliothèques Arduino requises :
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
// Data wire is connteced to the Arduino digital pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices:
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor:
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 20, 4);
int deviceCount = 0, i=0, N, L = 0, k;
float tempC ;
float tempF ;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
// Turn ON LCD
lcd.begin(20,4);
lcd.backlight();
lcd.clear();
// Start serial communication for debugging purposes
Serial.begin(9600);
lcd.setCursor(0,0);
lcd.print(" Salam Alaikum ");
lcd.setCursor(0,2);
lcd.print("Sensing Temperature");
// Start up the library
sensors.begin();
// localazing sensors in the bus
//Serial.println("Localisation des périphériques...");
//Serial.print("Trouvé ");
deviceCount = sensors.getDeviceCount();
//Serial.print(deviceCount);
//Serial.println(" devices");
N = 5;
if (N = 5) {
label1:
int a = digitalRead(3);
if (a == 1) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Number of Sensors:");
lcd.setCursor(0,1);
lcd.print(deviceCount);
lcd.print(" sensors");
N = 0;
delay (2000);
}
else { goto label1; }
}
}
void loop(void) {
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
label2:
int a = digitalRead(3);
if (a == 1 && N == 0) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Group A:");
k = 0; L = 3;
for (int i = k; i < L; i++) {
Serial.print("Sensor ");
Serial.print(i + 1);
Serial.print(" : ");
// Get temp for each sensor
tempC = sensors.getTempCByIndex(i);
tempF = sensors.getTempFByIndex(i);
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Serial.print(sensors.getTempCByIndex(0));
Serial.print(tempC); Serial.print(" \xC2\xB0"); Serial.print("C | "); // display ° symbol
Serial.print(tempF); Serial.print(" \xC2\xB0"); Serial.println("F");
lcd.setCursor(0,i+1);
lcd.print("T"); lcd.print(i+1);lcd.print(" = ");
lcd.print(tempC); lcd.print(" \xC2\xB0"); lcd.print("C | ");
//lcd.print(tempF); lcd.print(" \xC2\xB0"); lcd.print("F");
if (N <= 2) { N = N+1; }
else { N = 0; }
}
delay (2000);
}
else if (a == 1 && N == 1) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Group B:");
k = 3; L = 6;
for (int i = k; i < L; i++) {
Serial.print("Sensor ");
Serial.print(i + 1);
Serial.print(" : ");
// Get temp for each sensor
tempC = sensors.getTempCByIndex(i);
tempF = sensors.getTempFByIndex(i);
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Serial.print(sensors.getTempCByIndex(0));
Serial.print(tempC); Serial.print(" \xC2\xB0"); Serial.print("C | "); // display ° symbol
Serial.print(tempF); Serial.print(" \xC2\xB0"); Serial.println("F");
lcd.setCursor(0,i+1);
lcd.print("T"); lcd.print(i+1);lcd.print(" = ");
lcd.print(tempC); lcd.print(" \xC2\xB0"); lcd.print("C | ");
//lcd.print(tempF); lcd.print(" \xC2\xB0"); lcd.print("F");
if (N <= 2) { N = N+1; }
else { N = 0; }
}
delay (2000);
}
else if (a == 1 && N == 2) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Group C:");
k = 6; L = 9;
for (int i = k; i < L; i++) {
Serial.print("Sensor ");
Serial.print(i + 1);
Serial.print(" : ");
// Get temp for each sensor
tempC = sensors.getTempCByIndex(i);
tempF = sensors.getTempFByIndex(i);
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
//Serial.print(sensors.getTempCByIndex(0));
Serial.print(tempC); Serial.print(" \xC2\xB0"); Serial.print("C | "); // display ° symbol
Serial.print(tempF); Serial.print(" \xC2\xB0"); Serial.println("F");
lcd.setCursor(0,i+1);
lcd.print("T"); lcd.print(i+1);lcd.print(" = ");
lcd.print(tempC); lcd.print(" \xC2\xB0"); lcd.print("C | ");
//lcd.print(tempF); lcd.print(" \xC2\xB0"); lcd.print("F");
if (N <= 2) { N = N+1; }
else { N = 0; }
}
delay (2000);
}
else { goto label2; }
Serial.println();
delay(1000);
}