-
GAMEPOD.hu
Okos Otthon összefoglaló
Új hozzászólás Aktív témák
-
Dodi_30
újonc
válasz layerke #4002 üzenetére
Az enyém annyiban különbözik, hogy nem két érzékelő házasítása, hanem egy érzékelő és egy beavatkozó.
Összemásoltam a két Sketch-et (mindent a megfelelő szakaszba), de nem működik.
A Void Setup szakaszban kizártam a reed érzékelő gw.beegin() sorát, így legalább a relé vezérlés feléledt. Most tudom kapcsolgatni a Domoticz alól. Viszont az Arduino 4-es lábát hiába teszem le földre (reed szimulálása), a Domoticzban a hozzárendelt kijelző nem mutat változást.#include <MySigningNone.h>
#include <MyTransportNRF24.h>
#include <MyTransportRFM69.h>
#include <MyHwATMega328.h>
#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
#define RELAY_ON 0 // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay#define CHILD_ID 3
#define BUTTON_PIN 4 // Arduino Digital I/O pin for button/reed switch// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
// Select AtMega328 hardware profile
MyHwATMega328 hw;
// Construct MySensors library
MySensor gw(radio, hw);Bounce debouncer = Bounce();
int oldValue=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg(CHILD_ID,V_TRIPPED);void setup()
{
// Initialize library and add callback for incoming messages
gw.begin(incomingMessage, AUTO, true);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Relay", "1.0");// Fetch relay status
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
gw.present(sensor, S_LIGHT);
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, gw.loadState(sensor)?RELAY_ONELAY_OFF);
}
{// gw.begin();
// Setup the button
pinMode(BUTTON_PIN,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN,HIGH);// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
gw.present(CHILD_ID, S_DOOR);
}
}void loop()
{
// Alway process incoming messages whenever possible
gw.process();
}void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ONELAY_OFF);
// Store state in eeprom
gw.saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}{
debouncer.update();
// Get the update value
int value = debouncer.read();if (value != oldValue) {
// Send in the new value
gw.send(msg.set(value==HIGH ? 1 : 0));
oldValue = value;
}
}}
[ Szerkesztve ]
Új hozzászólás Aktív témák
- Luck Dragon: Asszociációs játék. :)
- Intel Core i5 / i7 / i9 "Alder Lake-Raptor Lake/Refresh" (LGA1700)
- LEGO klub
- A fociról könnyedén, egy baráti társaságban
- BestBuy ruhás topik
- Vodafone mobilszolgáltatások
- Milyen TV-t vegyek?
- Autós topik
- Elemlámpa, zseblámpa
- Renault, Dacia topik
- További aktív témák...