From 3eb2a581bba75adae772a109559244d3891112ea Mon Sep 17 00:00:00 2001 From: bach Date: Sun, 10 Dec 2023 12:47:03 +0100 Subject: [PATCH] 0.2 --- ...airchaud.ino => registre_airchaud_code.ino | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) rename registre_airchaud.ino => registre_airchaud_code.ino (74%) diff --git a/registre_airchaud.ino b/registre_airchaud_code.ino similarity index 74% rename from registre_airchaud.ino rename to registre_airchaud_code.ino index 5218440..76e96d6 100644 --- a/registre_airchaud.ino +++ b/registre_airchaud_code.ino @@ -3,31 +3,46 @@ #define MY_RADIO_RF24 // #define MY_RF24_PA_LEVEL RF24_PA_MIN // #define MY_RF24_PA_LEVEL RF24_PA_LOW -#define MY_RF24_PA_LEVEL RF24_PA_HIGH -//#define MY_RF24_PA_LEVEL RF24_PA_MAX +// #define MY_RF24_PA_LEVEL RF24_PA_HIGH +#define MY_RF24_PA_LEVEL RF24_PA_MAX #define MY_RF24_CHANNEL 14 #define MY_REPEATER_FEATURE +#define MY_DEFAULT_RX_LED_PIN A0 +#define MY_DEFAULT_TX_LED_PIN A1 +#define MY_DEFAULT_ERR_LED_PIN A2 + #include #include +// https://lastminuteengineers.com/multiple-ds18b20-arduino-tutorial/ +#include +#include + +// Data wire is plugged into port 11 on the Arduino +#define ONE_WIRE_BUS 7 +// Setup a oneWire instance to communicate with any OneWire devices +OneWire oneWire(ONE_WIRE_BUS); + +// Pass our oneWire reference to Dallas Temperature. +DallasTemperature sensors(&oneWire); + #define ROTATION_CHILD_ID 0 +#define CHILD_ID_TEMP 1 MyMessage dimmerMsg(ROTATION_CHILD_ID, V_DIMMER); MyMessage lightMsg(ROTATION_CHILD_ID, V_LIGHT); // we need init light message to make the dimmer appear in HA +MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); /* control a 28BYJ-48 stepper motor with ULN2003 driver board https://www.makerguides.com/28byj-48-stepper-motor-arduino-tutorial/ */ - #include "Stepper.h" - // Define number of steps per rotation: const int stepsPerRevolution = 2048; // can be 4096 - // ULN2003 Wiring: // Pin 3 to IN1 // Pin 4 to IN2 @@ -41,15 +56,21 @@ int prevDimValue=0; int newDimValue=0; char convBuffer[10]; + +float DTemp; +float old_DTemp; + + void presentation() { #ifdef MY_DEBUG Serial.println("- - - - - presentation - - - - -"); #endif - sendSketchInfo("Registre Air Chaud", "0.1"); + sendSketchInfo("Registre Air Chaud", "0.2"); present(ROTATION_CHILD_ID, S_DIMMER, "rotation"); + present(CHILD_ID_TEMP, S_TEMP, "Temperature"); } void setup() { @@ -63,12 +84,24 @@ void setup() { send(dimmerMsg.set(prevDimValue)); send(lightMsg.set(1)); + + sensors.begin(); } void loop() { #ifdef MY_DEBUG // Serial.println("- - - - - loop - - - - -"); #endif + + sensors.requestTemperatures(); + old_DTemp = DTemp; + DTemp = sensors.getTempCByIndex(0); + if (DTemp != old_DTemp && DTemp != -127) + { + send(msgTemp.set(DTemp, 1)); + old_DTemp = DTemp; + } + delay(5000); }