Untitled
unknown
plain_text
5 months ago
2.1 kB
1
Indexable
#include <Wire.h> #include "rgb_lcd.h" #define DEV_ID 0x90 >> 1 #define HEATING_PIN 18 // Broche pour le contrôle du chauffage (relais) rgb_lcd lcd; const int colorR = 126; const int colorG = 0; const int colorB = 255; const float tempSetPoint = 24.0; // Température de consigne pour couper le chauffage void setup() { Serial.begin(9600); Wire.begin(); // Configuration du DS1621 pour la conversion continue Wire.beginTransmission(DEV_ID); Wire.write(0xAC); // Accéder à la configuration Wire.write(0x02); // Activer la conversion continue Wire.endTransmission(); Wire.beginTransmission(DEV_ID); Wire.write(0xEE); // Démarrer la conversion Wire.endTransmission(); // Configuration de la broche du chauffage pinMode(HEATING_PIN, OUTPUT); digitalWrite(HEATING_PIN, HIGH); // Initialement allumé (chauffage actif) lcd.begin(16, 2); // Initialiser l'afficheur LCD lcd.setRGB(colorR, colorG, colorB); delay(1000); } void loop() { int8_t firstByte; int8_t secondByte; float temp = 0; delay(1000); // Lire la température Wire.beginTransmission(DEV_ID); Wire.write(0xAA); // Commande pour lire la température Wire.endTransmission(); Wire.requestFrom(DEV_ID, 2); // Demander deux octets firstByte = Wire.read(); // Octet de poids fort secondByte = Wire.read(); // Octet de poids faible (gère la fraction 0.5°C) // Calculer la température avec une précision de 0.5°C temp = firstByte; if (secondByte & 0x80) { // Si le bit 7 du second octet est à 1, ajouter 0.5°C temp += 0.5; } Serial.print("Température : "); Serial.println(temp); // Afficher la température sur le moniteur série // Contrôle du chauffage if (temp >= tempSetPoint) { digitalWrite(HEATING_PIN, LOW); // Couper le chauffage Serial.println("Chauffage éteint"); } else { digitalWrite(HEATING_PIN, HIGH); // Allumer le chauffage Serial.println("Chauffage allumé"); } // Afficher la température sur le LCD lcd.setCursor(0, 1); lcd.print(temp); delay(1000); }
Editor is loading...
Leave a Comment