Rolety zewnętrzne z...
 
Powiadomienia
Wyczyść wszystko

Domoticz Rolety zewnętrzne zrealizowane na Arduino maysensors

6 Wpisów
3 Użytkownicy
0 Likes
1,986 Wyświetleń
(@astra1121)
Wpisów: 2
Świeżak
Autor tematu
 

Witam 

Nie dawno zainteresował się tematem inteligentnego domu i w nowym domu wstawiłem rolety zewnętrzne z silnikami 230V do puszek elektrycznych mam poprowadzony kabel utp.

Napisałem program na podstawie maysensors i niby miało śmigać bez problemów, niestety tak nie było. podczas uruchomienia 1 rolety działało wszytko ok. roleta podnosiła się i opuszczała z przycisku i sterowana z Domoticza. 2 roleta działała z przycisku ale gdy starałem się sterować z domoticza to podnosiła się 1 i 2 . Po uruchomieniu trzeciej działała tylko po wysterowaniu z domoticza arduino nie reaguje na przycisk choć jest poprawnie podłączony. Teraz jestem w kropce :

1. czemu nie mogę sterować tylko pojedynczą roletą z domoticza ?

2. czemu adruino nie reaguje na kolejne przyciski ?

Zakładana specyfika pracy rolet :

1. Sterowanie każdej rolety z przycisku rolety mam tych rolet 9

2. Sterowanie każdej rolety z osobna jak i wszystkimi razem z domoticza.

3. Ustawić plan dla wszystkich rolet 

3 . W przyszłości sterowanie roletami z domoticza procentowo.

Proszę o radę czy z moim kodem jest wszystko ok i jak go mogę poprawć aby to działało.

#define MY_DEBUG
#define MY_GATEWAY_SERIAL
#define MY_REPEATER_FEATURE
//#include MY_NODE_ID 1

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>

//--------------Roleta 1-------------------------
#define BUTTON_PIN 4
#define RELAY_1 5
#define BUTTON_PIN2 6
#define RELAY_2 7
//--------------Roleta 2-------------------------
#define BUTTON_PIN3 8
#define RELAY_3 9
#define BUTTON_PIN4 10
#define RELAY_4 11
//--------------Roleta 3-------------------------
#define BUTTON_PIN5 12
#define RELAY_5 13
#define BUTTON_PIN6 14
#define RELAY_6 15
//--------------Roleta 4-------------------------
#define BUTTON_PIN7 16
#define RELAY_7 17
#define BUTTON_PIN8 18
#define RELAY_8 19
//--------------Roleta 5-------------------------
#define BUTTON_PIN9 20
#define RELAY_9 21
#define BUTTON_PIN10 22
#define RELAY_10 23
//--------------Roleta 6-------------------------
#define BUTTON_PIN11 24
#define RELAY_11 25
#define BUTTON_PIN12 26
#define RELAY_12 27
//--------------Roleta 7-------------------------
#define BUTTON_PIN13 28
#define RELAY_13 29
#define BUTTON_PIN14 30
#define RELAY_14 31
//--------------Roleta 8-------------------------
#define BUTTON_PIN15 32
#define RELAY_15 33
#define BUTTON_PIN16 34
#define RELAY_16 35
//--------------Roleta 9-------------------------
#define BUTTON_PIN17 36
#define RELAY_17 37
#define BUTTON_PIN18 38
#define RELAY_18 39
//----------------------------------------------------------------

#define RELAY_ON 0
#define RELAY_OFF 1

// Inicjalizacja obiektu Bounce
Bounce debouncer = Bounce();
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce();
Bounce debouncer4 = Bounce();
Bounce debouncer5 = Bounce();
Bounce debouncer6 = Bounce();
Bounce debouncer7 = Bounce();
Bounce debouncer8 = Bounce();
Bounce debouncer9 = Bounce();
Bounce debouncer10 = Bounce();
Bounce debouncer11 = Bounce();
Bounce debouncer12 = Bounce();
Bounce debouncer13 = Bounce();
Bounce debouncer14 = Bounce();
Bounce debouncer15 = Bounce();
Bounce debouncer16 = Bounce();
Bounce debouncer17 = Bounce();
Bounce debouncer18 = Bounce();

void before() {

  pinMode(RELAY_1, OUTPUT);
  pinMode(RELAY_2, OUTPUT);
  pinMode(RELAY_3, OUTPUT);
  pinMode(RELAY_4, OUTPUT);
  pinMode(RELAY_5, OUTPUT);
  pinMode(RELAY_6, OUTPUT);
  pinMode(RELAY_7, OUTPUT);
  pinMode(RELAY_8, OUTPUT);
  pinMode(RELAY_9, OUTPUT);
  pinMode(RELAY_10, OUTPUT);
  pinMode(RELAY_11, OUTPUT);
  pinMode(RELAY_12, OUTPUT);
  pinMode(RELAY_13, OUTPUT);
  pinMode(RELAY_14, OUTPUT);
  pinMode(RELAY_15, OUTPUT);
  pinMode(RELAY_16, OUTPUT);
  pinMode(RELAY_17, OUTPUT);
  pinMode(RELAY_18, OUTPUT);
  digitalWrite(RELAY_1, HIGH);
  digitalWrite(RELAY_2, HIGH);
  digitalWrite(RELAY_3, HIGH);
  digitalWrite(RELAY_4, HIGH);
  digitalWrite(RELAY_5, HIGH);
  digitalWrite(RELAY_6, HIGH);
  digitalWrite(RELAY_7, HIGH);
  digitalWrite(RELAY_8, HIGH);
  digitalWrite(RELAY_9, HIGH);
  digitalWrite(RELAY_10, HIGH);
  digitalWrite(RELAY_11, HIGH);
  digitalWrite(RELAY_12, HIGH);
  digitalWrite(RELAY_13, HIGH);
  digitalWrite(RELAY_14, HIGH);
  digitalWrite(RELAY_15, HIGH);
  digitalWrite(RELAY_16, HIGH);
  digitalWrite(RELAY_17, HIGH);
  digitalWrite(RELAY_18, HIGH);

}



void setup() {

  // Konfiguracja pinu przycisku i aktywowanie rezystora podciągającego:
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  pinMode(BUTTON_PIN3, INPUT_PULLUP);
  pinMode(BUTTON_PIN4, INPUT_PULLUP);
  pinMode(BUTTON_PIN5, INPUT_PULLUP);
  pinMode(BUTTON_PIN6, INPUT_PULLUP);
  pinMode(BUTTON_PIN7, INPUT_PULLUP);
  pinMode(BUTTON_PIN8, INPUT_PULLUP);
  pinMode(BUTTON_PIN9, INPUT_PULLUP);
  pinMode(BUTTON_PIN10, INPUT_PULLUP);
  pinMode(BUTTON_PIN11, INPUT_PULLUP);
  pinMode(BUTTON_PIN12, INPUT_PULLUP);
  pinMode(BUTTON_PIN13, INPUT_PULLUP);
  pinMode(BUTTON_PIN14, INPUT_PULLUP);
  pinMode(BUTTON_PIN15, INPUT_PULLUP);
  pinMode(BUTTON_PIN16, INPUT_PULLUP);
  pinMode(BUTTON_PIN17, INPUT_PULLUP);
  pinMode(BUTTON_PIN18, INPUT_PULLUP);
  // Po konfiguracji przycisku, ustawienie działania funkcji Bounce :
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(5); // interwał w ms
  debouncer2.attach(BUTTON_PIN2);
  debouncer2.interval(5);
  debouncer3.attach(BUTTON_PIN3);
  debouncer3.interval(5); // interwał w ms
  debouncer4.attach(BUTTON_PIN4);
  debouncer4.interval(5);
  debouncer5.attach(BUTTON_PIN5);
  debouncer5.interval(5);
  debouncer6.attach(BUTTON_PIN6);
  debouncer6.interval(5);
  debouncer7.attach(BUTTON_PIN7);
  debouncer7.interval(5);
  debouncer8.attach(BUTTON_PIN8);
  debouncer8.interval(5);
  debouncer9.attach(BUTTON_PIN9);
  debouncer9.interval(5);
  debouncer10.attach(BUTTON_PIN10);
  debouncer10.interval(5);
  debouncer11.attach(BUTTON_PIN11);
  debouncer11.interval(5);
  debouncer12.attach(BUTTON_PIN12);
  debouncer12.interval(5);
  debouncer13.attach(BUTTON_PIN13);
  debouncer13.interval(5);
  debouncer14.attach(BUTTON_PIN14);
  debouncer14.interval(5);
  debouncer15.attach(BUTTON_PIN15);
  debouncer15.interval(5);
  debouncer16.attach(BUTTON_PIN16);
  debouncer16.interval(5);
  debouncer17.attach(BUTTON_PIN17);
  debouncer17.interval(5);
  debouncer18.attach(BUTTON_PIN18);
  debouncer18.interval(5);

}


void presentation()
{
  sendSketchInfo("Roller shutter", "1.0");

  int sensor = 1;
  present(sensor, S_COVER);

  int sensor2 = 2 ;
  present(sensor2, S_COVER);

  int sensor3 = 3 ;
  present(sensor3, S_COVER);

  int sensor4 = 4 ;
  present(sensor4, S_COVER);

  int sensor5 = 5 ;
  present(sensor5, S_COVER);

  int sensor6 = 6 ;
  present(sensor6, S_COVER);

  int sensor7 = 7 ;
  present(sensor7, S_COVER);

  int sensor8 = 8 ;
  present(sensor8, S_COVER);

  int sensor9 = 9 ;
  present(sensor9, S_COVER);

  int sensor10 = 10 ;
  present(sensor10, S_COVER);

  int sensor11 = 11 ;
  present(sensor11, S_COVER);

  int sensor12 = 12 ;
  present(sensor12, S_COVER);

  int sensor13 = 13 ;
  present(sensor13, S_COVER);

  int sensor14 = 14 ;
  present(sensor14, S_COVER);

  int sensor15 = 15 ;
  present(sensor15, S_COVER);

  int sensor16 = 16 ;
  present(sensor16, S_COVER);

  int sensor17 = 17 ;
  present(sensor17, S_COVER);

  int sensor18 = 18 ;
  present(sensor18, S_COVER);


}

MyMessage msg(1, V_LIGHT);
MyMessage msg2(2, V_LIGHT);
MyMessage msg3(3, V_LIGHT);
MyMessage msg4(4, V_LIGHT);
MyMessage msg5(5, V_LIGHT);
MyMessage msg6(6, V_LIGHT);
MyMessage msg7(7, V_LIGHT);
MyMessage msg8(8, V_LIGHT);
MyMessage msg9(9, V_LIGHT);
MyMessage msg10(10, V_LIGHT);
MyMessage msg11(11, V_LIGHT);
MyMessage msg12(12, V_LIGHT);
MyMessage msg13(13, V_LIGHT);
MyMessage msg14(14, V_LIGHT);
MyMessage msg15(15, V_LIGHT);
MyMessage msg16(16, V_LIGHT);
MyMessage msg17(17, V_LIGHT);
MyMessage msg18(18, V_LIGHT);

void loop() {

  // debouncer.update();
  //debouncer2.update();
  // debouncer3.update();
  //debouncer4.update();

  //-----------------------------------------------------------------

  if (debouncer.update()) {
    int value = debouncer.read();
    if (value == HIGH) {
      saveState(1, !loadState(1));
      digitalWrite(RELAY_1, loadState(1) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_2, HIGH);
      send(msg.set(loadState(1)));
    }
  }
  if (debouncer2.update()) {
    int value2 = debouncer2.read();
    if (value2 == LOW) {
      saveState(2, !loadState(2));
      digitalWrite(RELAY_2, loadState(2) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_1, HIGH);
      send(msg.set(loadState(2)));
    }
  }
    
  //-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer3.update()) {
    // Get the update value.
    int value3 = debouncer3.read();
    // Send in the new value.
    if (value3 == LOW) {
      saveState(3, !loadState(3));
      digitalWrite(RELAY_3, loadState(3) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_4, HIGH);
      send(msg3.set(loadState(3)));
    }
  }
  if (debouncer4.update()) {
    int value4 = debouncer4.read();
    if (value4 == LOW) {
      saveState(4, !loadState(4));
      digitalWrite(RELAY_4, loadState(4) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_3, HIGH);
      send(msg4.set(loadState(4)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer5.update()) {
    // Get the update value.
    int value5 = debouncer5.read();
    // Send in the new value.
    if (value5 == LOW) {
      saveState(5, !loadState(5));
      digitalWrite(RELAY_5, loadState(5) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_6, HIGH);
      send(msg5.set(loadState(5)));
    }
  }
  if (debouncer6.update()) {
    int value6 = debouncer6.read();
    if (value6 == LOW) {
      saveState(6, !loadState(6));
      digitalWrite(RELAY_6, loadState(6) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_5, HIGH);
      send(msg6.set(loadState(6)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer7.update()) {
    // Get the update value.
    int value7 = debouncer7.read();
    // Send in the new value.
    if (value7 == LOW) {
      saveState(7, !loadState(7));
      digitalWrite(RELAY_7, loadState(7) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_8, HIGH);
      send(msg7.set(loadState(7)));
    }
  }
  if (debouncer8.update()) {
    int value8 = debouncer8.read();
    if (value8 == LOW) {
      saveState(8, !loadState(8));
      digitalWrite(RELAY_8, loadState(8) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_7, HIGH);
      send(msg8.set(loadState(8)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer9.update()) {
    // Get the update value.
    int value9 = debouncer9.read();
    // Send in the new value.
    if (value9 == LOW) {
      saveState(9, !loadState(9));
      digitalWrite(RELAY_9, loadState(9) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_10, HIGH);
      send(msg9.set(loadState(9)));
    }
  }
  if (debouncer10.update()) {
    int value10 = debouncer10.read();
    if (value10 == LOW) {
      saveState(10, !loadState(10));
      digitalWrite(RELAY_10, loadState(10) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_9, HIGH);
      send(msg10.set(loadState(10)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer11.update()) {
    // Get the update value.
    int value11 = debouncer11.read();
    // Send in the new value.
    if (value11 == LOW) {
      saveState(11, !loadState(11));
      digitalWrite(RELAY_11, loadState(11) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_12, HIGH);
      send(msg11.set(loadState(11)));
    }
  }
  if (debouncer12.update()) {
    int value12 = debouncer12.read();
    if (value12 == LOW) {
      saveState(12, !loadState(12));
      digitalWrite(RELAY_12, loadState(12) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_11, HIGH);
      send(msg12.set(loadState(12)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer13.update()) {
    // Get the update value.
    int value13 = debouncer13.read();
    // Send in the new value.
    if (value13 == LOW) {
      saveState(13, !loadState(13));
      digitalWrite(RELAY_13, loadState(13) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_14, HIGH);
      send(msg13.set(loadState(13)));
    }
  }
  if (debouncer14.update()) {
    int value14 = debouncer14.read();
    if (value14 == LOW) {
      saveState(14, !loadState(14));
      digitalWrite(RELAY_14, loadState(14) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_13, HIGH);
      send(msg14.set(loadState(14)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer15.update()) {
    // Get the update value.
    int value15 = debouncer15.read();
    // Send in the new value.
    if (value15 == LOW) {
      saveState(15, !loadState(15));
      digitalWrite(RELAY_15, loadState(15) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_16, HIGH);
      send(msg15.set(loadState(15)));
    }
  }
  if (debouncer16.update()) {
    int value16 = debouncer16.read();
    if (value16 == LOW) {
      saveState(16, !loadState(16));
      digitalWrite(RELAY_16, loadState(16) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_15, HIGH);
      send(msg16.set(loadState(16)));
    }
  }
//-----------------------------------------------------------------
  // Send locally attached sensor data here
  if (debouncer17.update()) {
    // Get the update value.
    int value17 = debouncer17.read();
    // Send in the new value.
    if (value17 == LOW) {
      saveState(17, !loadState(17));
      digitalWrite(RELAY_17, loadState(17) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_18, HIGH);
      send(msg17.set(loadState(17)));
    }
  }
  if (debouncer18.update()) {
    int value18 = debouncer18.read();
    if (value18 == LOW) {
      saveState(18, !loadState(18));
      digitalWrite(RELAY_18, loadState(18) ? RELAY_ON : RELAY_OFF);
      digitalWrite(RELAY_17, HIGH);
      send(msg18.set(loadState(18)));
    }
  }

}

void receive(const MyMessage &message) {

  {
    if (message.type == V_UP) {
      digitalWrite(RELAY_1, HIGH);
      digitalWrite(RELAY_2, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_1, HIGH);
      digitalWrite(RELAY_2, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_2, HIGH);
      digitalWrite(RELAY_1, LOW);
    }
  }

  {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_3, HIGH);
      digitalWrite(RELAY_4, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_3, HIGH);
      digitalWrite(RELAY_4, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_4, HIGH);
      digitalWrite(RELAY_3, LOW);
    }
  }
  {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_5, HIGH);
      digitalWrite(RELAY_6, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_5, HIGH);
      digitalWrite(RELAY_6, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_6, HIGH);
      digitalWrite(RELAY_5, LOW);
    }
  }
  {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_7, HIGH);
      digitalWrite(RELAY_8, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_7, HIGH);
      digitalWrite(RELAY_8, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_8, HIGH);
      digitalWrite(RELAY_7, LOW);
    }
  }
    {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_9, HIGH);
      digitalWrite(RELAY_10, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_9, HIGH);
      digitalWrite(RELAY_10, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_10, HIGH);
      digitalWrite(RELAY_9, LOW);
    }
  }
    {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_11, HIGH);
      digitalWrite(RELAY_12, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_11, HIGH);
      digitalWrite(RELAY_12, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_12, HIGH);
      digitalWrite(RELAY_11, LOW);
    }
  }
    {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_13, HIGH);
      digitalWrite(RELAY_14, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_13, HIGH);
      digitalWrite(RELAY_14, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_14, HIGH);
      digitalWrite(RELAY_13, LOW);
    }
  }
    {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_15, HIGH);
      digitalWrite(RELAY_16, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_15, HIGH);
      digitalWrite(RELAY_16, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_16, HIGH);
      digitalWrite(RELAY_15, LOW);
    }
  }
    {
    //----------------------------------------------------------
    if (message.type == V_UP) {
      digitalWrite(RELAY_17, HIGH);
      digitalWrite(RELAY_18, LOW);
    }
    if (message.type == V_STOP ) {
      digitalWrite(RELAY_17, HIGH);
      digitalWrite(RELAY_18, HIGH);
    }
    if (message.type == V_DOWN) {
      digitalWrite(RELAY_18, HIGH);
      digitalWrite(RELAY_17, LOW);
    }
  }
  
}
 
Dodane : 31/03/2021 8:19 pm
(@kuerten)
Wpisów: 8
Bywalec
 

Hmm

Całkiem podobny skrypt do tego, który tworzyłem jakiś czas temu. Kilka dni temu sam chciałem go zastosować u siebie w domu i jakoś nie wyszło. Pewnie nie wyłapałem błędów wcześniej bo testowałem wszystko na jednej rolecie. A w domu już ich jest 24. Na dzień dzisiejszy nie wiem gdzie jest błąd bo nie jestem programistą ale jest kilka nie logicznych rzeczy w skrypcie. 

1. Jeżeli przycisk wciśniemy to zapamięta on jego stan ( powinno być raczej high niż low) i przełączy przekaźnik. Za pierwszym razem da na przekaźnik napięcie. Za drugim naciśnięciem znowu Arduino wykryje stan wysoki na przycisku ale na przekaźnik nie popłynie napięcie bo zmieni jego stan. 

2. W tej samej części kodu jeśli roleta na być za sterowana do góry to drugi przekaźnik musi być wyłączony dlatego jest relay2 = high ( lepiej było wpisać low wtedy wiemy że chodzi o jego wyłączenie)

3. Jeżeli naciśniesz przycisk opuszczania to Arduino wykryje stan wysoki i wykona na przekaźniku opuszczania stan ??? odwrotny do tego, który był na początku ?

Problem jest w tym, że on ma w pamięci stanu, który zapamiętał z pierwszego wciśnięcia przycisku. 

Ta opcja z drugim przekaźnikiem miała zabezpieczać roletę przed jednoczesnym za sterowaniem góra, dół.

Lepsze było by uzależnienie

#define MY_DEBUG
#define MY_GATEWAY_SERIAL
#define MY_REPEATER_FEATURE

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h> 

//--------------Roleta w kuchni duże okno-------------------------
#define ROLETA_1_CHILD 1
#define BUTTON_PIN A1
#define BUTTON_PIN2 A2
#define RELAY_1  2
#define RELAY_2  5

bool state = false;
bool initialValueSent = false;
int poprzedni_stan_RELAY_1 = LOW;
int poprzedni_stan_RELAY_2 = LOW;
int stan_RELAY_1 = LOW;
int stan_RELAY_2 = LOW;
//----------------------------------------------------------------

// Inicjalizacja obiektu Bounce
Bounce debouncer = Bounce(); 
Bounce debouncer2 = Bounce();


void before() {

  pinMode(RELAY_1, OUTPUT);
  pinMode(RELAY_2, OUTPUT);
;
  digitalWrite(RELAY_1,LOW);
  digitalWrite(RELAY_2,LOW);
}



void setup() {

// Konfiguracja pinu przycisku i aktywowanie rezystora podciągającego:
  pinMode(BUTTON_PIN,INPUT_PULLUP);
  pinMode(BUTTON_PIN2,INPUT_PULLUP);

  
// Po konfiguracji przycisku, ustawienie działania funkcji Bounce :
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(20); 
  debouncer2.attach(BUTTON_PIN2);
  debouncer2.interval(20);
 
  
}


void presentation()
{
  sendSketchInfo("Rolety parter", "1.0");
  
 present(ROLETA_1_CHILD, S_BINARY);

}

MyMessage msg(ROLETA_1_CHILD, V_STATUS);
MyMessage msg2(ROLETA_1_CHILD, V_STATUS);


void loop() {




//--------------Roleta w kuchni duże okno-------------------------
  if (debouncer.update())  {
    int value = debouncer.read();
    if(value == HIGH && poprzedni_stan_RELAY_1 == LOW && stan_RELAY_2 == LOW){
      if(stan_RELAY_1 == HIGH){
        stan_RELAY_1 = LOW;
      } else {
        stan_RELAY_1 = HIGH;
      }}
      digitalWrite(RELAY_1, stan_RELAY_1);
      poprzedni_stan_RELAY_1 == value;
      send(msg.set(stan_RELAY_1), true);
}

  if (debouncer2.update())  {
    int value2 = debouncer2.read();
    if(value2 == HIGH && poprzedni_stan_RELAY_2 == LOW && stan_RELAY_1 == LOW){
      if(stan_RELAY_2 == HIGH){
        stan_RELAY_2 = LOW;
      } else {
        stan_RELAY_2 = HIGH;
      }}
      digitalWrite(RELAY_2, stan_RELAY_2);
      poprzedni_stan_RELAY_2 == value2;
send(msg2.set(stan_RELAY_2), true);
  }

}
 void receive(const MyMessage &message) {
  
//--------------Roleta w kuchni duże okno-------------------------
  {
  if (message.sensor == ROLETA_1_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_1, HIGH);
    digitalWrite(RELAY_2, LOW);
  }
  }
  if (message.sensor == ROLETA_1_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_1, LOW);
    digitalWrite(RELAY_2, LOW);
  }
  }
  if (message.sensor == ROLETA_1_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_2, HIGH);
    digitalWrite(RELAY_1, LOW);
  }
  }
  }
 } 

Nie sprawdzałem tego pod domoticzem. Na przekaźnikach jest dobrze zabezpieczone jednoczesne załączenie góra, dół. Daj znać czy domoticz to widzi bo ja szukam czegoś pod HA a tutaj jest problem innej natury.

pozdro

 
Dodane : 06/04/2021 7:53 pm
(@szmydu)
Wpisów: 68
Kontrybutor
 

Cześć, jak chcesz to mam gotowy skrypt do obsługi rolet przez MySensors. U mnie sterowanie odbywa się przy użyciu włączników zwiernych do rolet i zwykłych przekaźników SSR (2 szt. na jedną roletę). Mam 6 rolet. Pomimo, że skrypt ma zaimplementowaną obsługę % to niestety w domoticzu to nie działa. Skrypt nie jest mojego auotrstwa, lecz natrafiłem na niego w internecie 🙂

 
Dodane : 14/04/2021 11:49 am
(@kuerten)
Wpisów: 8
Bywalec
 

@szmydu

Jasne.

Zapodaj skryptem, chętnie zobaczę jak to jest napisane 🙂

 
Dodane : 14/04/2021 12:18 pm
(@szmydu)
Wpisów: 68
Kontrybutor
 

 

W szkicu oprócz rolet mam też zrobioną obsługę włączników schodowych i dzwonka. Dużo zabawy byłoby z kasowaniem tego więc wrzucam całość. Może przy okazji ktoś wyłapie dlaczego procentowe sterowanie nie działa w Domoticzu, z tego co kojarzę to szkic pisany był pod Home Assitant. 

 
Dodane : 14/04/2021 1:39 pm
(@kuerten)
Wpisów: 8
Bywalec
 

Trochę odświeżę temat. Wklejam szkic do sterowania roletami, którego używam od roku. Sterowanie z poziomu domoticza działa bez zarzutu. Do sterowania mechanicznego używam przycisków dzwonkowych góra/dół (bez przycisku stop). Czasami trzeba nacisnąć dwa razy przycisk w danym kierunku, żeby roleta ruszyła. Rozumiem, że jest to spowodowane jakimś stanem, który został w pamięci np. z poprzedniej komendy z poziomu domoticza. Inna niedoróbka to taka, że jeżeli zasterujemy przyciskiem np. w górę to tylko przyciskiem w górę zatrzymamy roletę. Jeżeli, ktoś jest na tyle biegły w pisaniu programów i może naprawić te błędy to będzie dla przyszłych pokoleń.

#define MY_DEBUG
#define MY_GATEWAY_SERIAL
#define MY_REPEATER_FEATURE

#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h> 

//--------------Roleta w kuchni duże okno-------------------------
#define ROLETA_1_CHILD 1
#define BUTTON_PIN A1
#define BUTTON_PIN2 A2
#define RELAY_1  2
#define RELAY_2  3
//--------------Roleta w kuchni małe okno-------------------------
#define ROLETA_2_CHILD 2
#define BUTTON_PIN3 A3
#define BUTTON_PIN4 A4
#define RELAY_3  4
#define RELAY_4  5
//--------------Roleta w jadalni duże okno------------------------
#define ROLETA_3_CHILD 3
#define BUTTON_PIN5 A5
#define BUTTON_PIN6 A6
#define RELAY_5  6
#define RELAY_6  7
//--------------Roleta w jadalni małe okno------------------------
#define ROLETA_4_CHILD 4
#define BUTTON_PIN7 A7
#define BUTTON_PIN8 A8
#define RELAY_7  8
#define RELAY_8  9
//--------------Roleta w dużym pokoju duże okno od frontu---------
#define ROLETA_5_CHILD 5
#define BUTTON_PIN9 A9
#define BUTTON_PIN10 A10
#define RELAY_9  10
#define RELAY_10 11
//--------------Roleta w dużym pokoju małe okno od frontu---------
#define ROLETA_6_CHILD 6
#define BUTTON_PIN11 A11
#define BUTTON_PIN12 A12
#define RELAY_11  12
#define RELAY_12  13
//--------------Roleta w dużym pokoju małe okno od strony ogrodu--
#define ROLETA_7_CHILD 7
#define BUTTON_PIN13 A13
#define BUTTON_PIN14 A14
#define RELAY_13  14
#define RELAY_14  15
//--------------Roleta w dużym pokoju drzwi tarasowe--------------
#define ROLETA_8_CHILD 8
#define BUTTON_PIN15 A15
#define BUTTON_PIN16 52
#define RELAY_15  16
#define RELAY_16  17
//--------------Roleta w gabinecie drzwi tarasowe-----------------
#define ROLETA_9_CHILD 9
#define BUTTON_PIN17 51
#define BUTTON_PIN18 50
#define RELAY_17  18
#define RELAY_18  19
//--------------Roleta w gabinecie okno---------------------------
#define ROLETA_10_CHILD 10
#define BUTTON_PIN19 49
#define BUTTON_PIN20 48
#define RELAY_19  20
#define RELAY_20  21
//--------------Roleta w łazience na parterze---------------------
#define ROLETA_11_CHILD 11
#define BUTTON_PIN21 47
#define BUTTON_PIN22 46
#define RELAY_21  22
#define RELAY_22  23
//--------------Roleta w pomieszczeniu gospodarczym---------------
#define ROLETA_12_CHILD 12
#define BUTTON_PIN23 45
#define BUTTON_PIN24 44
#define RELAY_23  24
#define RELAY_24  25
//--------------Roleta w garażu-----------------------------------
#define ROLETA_13_CHILD 13
#define BUTTON_PIN25 43
#define BUTTON_PIN26 42
#define RELAY_25  26
#define RELAY_26  27
//--------------Brama garażowa------------------------------------
#define ROLETA_14_CHILD 14
#define BUTTON_PIN27 41
#define BUTTON_PIN28 40
#define RELAY_27  28
#define RELAY_28  29
//----------------------------------------------------------------

#define RELAY_ON 1  
#define RELAY_OFF 0

//----------------------------------------------------------------

// Inicjalizacja obiektu Bounce
Bounce debouncer = Bounce(); 
Bounce debouncer2 = Bounce();
Bounce debouncer3 = Bounce(); 
Bounce debouncer4 = Bounce();
Bounce debouncer5 = Bounce(); 
Bounce debouncer6 = Bounce();
Bounce debouncer7 = Bounce(); 
Bounce debouncer8 = Bounce();
Bounce debouncer9 = Bounce(); 
Bounce debouncer10 = Bounce();
Bounce debouncer11 = Bounce(); 
Bounce debouncer12 = Bounce();
Bounce debouncer13 = Bounce(); 
Bounce debouncer14 = Bounce();
Bounce debouncer15 = Bounce(); 
Bounce debouncer16 = Bounce();
Bounce debouncer17 = Bounce(); 
Bounce debouncer18 = Bounce();
Bounce debouncer19 = Bounce(); 
Bounce debouncer20 = Bounce();
Bounce debouncer21 = Bounce(); 
Bounce debouncer22 = Bounce();
Bounce debouncer23 = Bounce(); 
Bounce debouncer24 = Bounce();
Bounce debouncer25 = Bounce(); 
Bounce debouncer26 = Bounce();
Bounce debouncer27 = Bounce(); 
Bounce debouncer28 = Bounce();

void before() {

  pinMode(RELAY_1, OUTPUT);
  pinMode(RELAY_2, OUTPUT);
  pinMode(RELAY_3, OUTPUT);
  pinMode(RELAY_4, OUTPUT);
  pinMode(RELAY_5, OUTPUT);
  pinMode(RELAY_6, OUTPUT);
  pinMode(RELAY_7, OUTPUT);
  pinMode(RELAY_8, OUTPUT);
  pinMode(RELAY_9, OUTPUT);
  pinMode(RELAY_10, OUTPUT);
  pinMode(RELAY_11, OUTPUT);
  pinMode(RELAY_12, OUTPUT);
  pinMode(RELAY_13, OUTPUT);
  pinMode(RELAY_14, OUTPUT);
  pinMode(RELAY_15, OUTPUT);
  pinMode(RELAY_16, OUTPUT);
  pinMode(RELAY_17, OUTPUT);
  pinMode(RELAY_18, OUTPUT);
  pinMode(RELAY_19, OUTPUT);
  pinMode(RELAY_20, OUTPUT);
  pinMode(RELAY_21, OUTPUT);
  pinMode(RELAY_22, OUTPUT);
  pinMode(RELAY_23, OUTPUT);
  pinMode(RELAY_24, OUTPUT);
  pinMode(RELAY_25, OUTPUT);
  pinMode(RELAY_26, OUTPUT);
  pinMode(RELAY_27, OUTPUT);
  pinMode(RELAY_28, OUTPUT);
  digitalWrite(RELAY_1,LOW);
  digitalWrite(RELAY_2,LOW);
  digitalWrite(RELAY_3,LOW);
  digitalWrite(RELAY_4,LOW);
  digitalWrite(RELAY_5,LOW);
  digitalWrite(RELAY_6,LOW);
  digitalWrite(RELAY_7,LOW);
  digitalWrite(RELAY_8,LOW);
  digitalWrite(RELAY_9,LOW);
  digitalWrite(RELAY_10,LOW);
  digitalWrite(RELAY_11,LOW);
  digitalWrite(RELAY_12,LOW);
  digitalWrite(RELAY_13,LOW);
  digitalWrite(RELAY_14,LOW);
  digitalWrite(RELAY_15,LOW);
  digitalWrite(RELAY_16,LOW);
  digitalWrite(RELAY_17,LOW);
  digitalWrite(RELAY_18,LOW);
  digitalWrite(RELAY_19,LOW);
  digitalWrite(RELAY_20,LOW);
  digitalWrite(RELAY_21,LOW);
  digitalWrite(RELAY_22,LOW);
  digitalWrite(RELAY_23,LOW);
  digitalWrite(RELAY_24,LOW);
  digitalWrite(RELAY_25,LOW);
  digitalWrite(RELAY_26,LOW);
  digitalWrite(RELAY_27,LOW);
  digitalWrite(RELAY_28,LOW);

}



void setup() {

// Konfiguracja pinu przycisku i aktywowanie rezystora podciągającego:
  pinMode(BUTTON_PIN,INPUT_PULLUP);
  pinMode(BUTTON_PIN2,INPUT_PULLUP);
  pinMode(BUTTON_PIN3,INPUT_PULLUP);
  pinMode(BUTTON_PIN4,INPUT_PULLUP);
  pinMode(BUTTON_PIN5,INPUT_PULLUP);
  pinMode(BUTTON_PIN6,INPUT_PULLUP);
  pinMode(BUTTON_PIN7,INPUT_PULLUP);
  pinMode(BUTTON_PIN8,INPUT_PULLUP);
  pinMode(BUTTON_PIN9,INPUT_PULLUP);
  pinMode(BUTTON_PIN10,INPUT_PULLUP);
  pinMode(BUTTON_PIN11,INPUT_PULLUP);
  pinMode(BUTTON_PIN12,INPUT_PULLUP);
  pinMode(BUTTON_PIN13,INPUT_PULLUP);
  pinMode(BUTTON_PIN14,INPUT_PULLUP);
  pinMode(BUTTON_PIN15,INPUT_PULLUP);
  pinMode(BUTTON_PIN16,INPUT_PULLUP);
  pinMode(BUTTON_PIN17,INPUT_PULLUP);
  pinMode(BUTTON_PIN18,INPUT_PULLUP);
  pinMode(BUTTON_PIN19,INPUT_PULLUP);
  pinMode(BUTTON_PIN20,INPUT_PULLUP);
  pinMode(BUTTON_PIN21,INPUT_PULLUP);
  pinMode(BUTTON_PIN22,INPUT_PULLUP);
  pinMode(BUTTON_PIN23,INPUT_PULLUP);
  pinMode(BUTTON_PIN24,INPUT_PULLUP);
  pinMode(BUTTON_PIN25,INPUT_PULLUP);
  pinMode(BUTTON_PIN26,INPUT_PULLUP);
  pinMode(BUTTON_PIN27,INPUT_PULLUP);
  pinMode(BUTTON_PIN28,INPUT_PULLUP);
  
// Po konfiguracji przycisku, ustawienie działania funkcji Bounce :
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(5); 
  debouncer2.attach(BUTTON_PIN2);
  debouncer2.interval(5);
  debouncer3.attach(BUTTON_PIN3);
  debouncer3.interval(5);
  debouncer4.attach(BUTTON_PIN4);
  debouncer4.interval(5);
  debouncer5.attach(BUTTON_PIN5);
  debouncer5.interval(5); 
  debouncer6.attach(BUTTON_PIN6);
  debouncer6.interval(5); 
  debouncer7.attach(BUTTON_PIN7);
  debouncer7.interval(5); 
  debouncer8.attach(BUTTON_PIN8);
  debouncer8.interval(5); 
  debouncer9.attach(BUTTON_PIN9);
  debouncer9.interval(5); 
  debouncer10.attach(BUTTON_PIN10);
  debouncer10.interval(5); 
  debouncer11.attach(BUTTON_PIN11);
  debouncer11.interval(5); 
  debouncer12.attach(BUTTON_PIN12);
  debouncer12.interval(5); 
  debouncer13.attach(BUTTON_PIN13);
  debouncer13.interval(5); 
  debouncer14.attach(BUTTON_PIN14);
  debouncer14.interval(5); 
  debouncer15.attach(BUTTON_PIN15);
  debouncer15.interval(5); 
  debouncer16.attach(BUTTON_PIN16);
  debouncer16.interval(5); 
  debouncer17.attach(BUTTON_PIN17);
  debouncer17.interval(5); 
  debouncer18.attach(BUTTON_PIN18);
  debouncer18.interval(5); 
  debouncer19.attach(BUTTON_PIN19);
  debouncer19.interval(5); 
  debouncer20.attach(BUTTON_PIN20);
  debouncer20.interval(5); 
  debouncer21.attach(BUTTON_PIN21);
  debouncer21.interval(5); 
  debouncer22.attach(BUTTON_PIN22);
  debouncer22.interval(5); 
  debouncer23.attach(BUTTON_PIN23);
  debouncer23.interval(5); 
  debouncer24.attach(BUTTON_PIN24);
  debouncer24.interval(5); 
  debouncer25.attach(BUTTON_PIN25);
  debouncer25.interval(5); 
  debouncer26.attach(BUTTON_PIN26);
  debouncer26.interval(5); 
  debouncer27.attach(BUTTON_PIN27);
  debouncer27.interval(5); 
  debouncer28.attach(BUTTON_PIN28);
  debouncer28.interval(5); 
  
  
}


void presentation()
{
  sendSketchInfo("Rolety parter", "1.0");
  
 present(ROLETA_1_CHILD, S_COVER);
 present(ROLETA_2_CHILD, S_COVER);
 present(ROLETA_3_CHILD, S_COVER);
 present(ROLETA_4_CHILD, S_COVER);
 present(ROLETA_5_CHILD, S_COVER);
 present(ROLETA_6_CHILD, S_COVER);
 present(ROLETA_7_CHILD, S_COVER);
 present(ROLETA_8_CHILD, S_COVER);
 present(ROLETA_9_CHILD, S_COVER);
 present(ROLETA_10_CHILD, S_COVER);
 present(ROLETA_11_CHILD, S_COVER);
 present(ROLETA_12_CHILD, S_COVER);
 present(ROLETA_13_CHILD, S_COVER);
 present(ROLETA_14_CHILD, S_COVER);

}

MyMessage msg(ROLETA_1_CHILD, V_UP);
MyMessage msg2(ROLETA_1_CHILD, V_DOWN);
MyMessage msg3(ROLETA_2_CHILD, V_UP);
MyMessage msg4(ROLETA_2_CHILD, V_DOWN);
MyMessage msg5(ROLETA_3_CHILD, V_UP);
MyMessage msg6(ROLETA_3_CHILD, V_DOWN);
MyMessage msg7(ROLETA_4_CHILD, V_UP);
MyMessage msg8(ROLETA_4_CHILD, V_DOWN);
MyMessage msg9(ROLETA_5_CHILD, V_UP);
MyMessage msg10(ROLETA_5_CHILD, V_DOWN);
MyMessage msg11(ROLETA_6_CHILD, V_UP);
MyMessage msg12(ROLETA_6_CHILD, V_DOWN);
MyMessage msg13(ROLETA_7_CHILD, V_UP);
MyMessage msg14(ROLETA_7_CHILD, V_DOWN);
MyMessage msg15(ROLETA_8_CHILD, V_UP);
MyMessage msg16(ROLETA_8_CHILD, V_DOWN);
MyMessage msg17(ROLETA_9_CHILD, V_UP);
MyMessage msg18(ROLETA_9_CHILD, V_DOWN);
MyMessage msg19(ROLETA_10_CHILD, V_UP);
MyMessage msg20(ROLETA_10_CHILD, V_DOWN);
MyMessage msg21(ROLETA_11_CHILD, V_UP);
MyMessage msg22(ROLETA_11_CHILD, V_DOWN);
MyMessage msg23(ROLETA_12_CHILD, V_UP);
MyMessage msg24(ROLETA_12_CHILD, V_DOWN);
MyMessage msg25(ROLETA_13_CHILD, V_UP);
MyMessage msg26(ROLETA_13_CHILD, V_DOWN);
MyMessage msg27(ROLETA_14_CHILD, V_UP);
MyMessage msg28(ROLETA_14_CHILD, V_DOWN);

void loop() {

//--------------Roleta w kuchni duże okno-------------------------

  if (debouncer.update()) {
    int value = debouncer.read();
    if((value == LOW) && (digitalRead(RELAY_2) == RELAY_OFF)){
         saveState(1, !loadState(1));
         digitalWrite(RELAY_1, loadState(1)?RELAY_ON:RELAY_OFF);
         send(msg.set(loadState(1)));
         }
  }
  if (debouncer2.update()) {
      int value2 = debouncer2.read();
    if((value2 == LOW) && (digitalRead(RELAY_1) == RELAY_OFF)){
         saveState(2, !loadState(2));
         digitalWrite(RELAY_2, loadState(2)?RELAY_ON:RELAY_OFF);
         send(msg2.set(loadState(2)));
         }
  }
//--------------Roleta w kuchni małe okno-------------------------
     // Send locally attached sensor data here 
  if (debouncer3.update()) {
    // Get the update value.
    int value3 = debouncer3.read();
    // Send in the new value.
    if((value3 == LOW) && (digitalRead(RELAY_4) == RELAY_OFF)){
         saveState(3, !loadState(3));
         digitalWrite(RELAY_3, loadState(3)?RELAY_ON:RELAY_OFF);
         send(msg3.set(loadState(3)));
         }
  }
  if (debouncer4.update()) {
      int value4 = debouncer4.read();
    if((value4 == LOW) && (digitalRead(RELAY_3) == RELAY_OFF)){
         saveState(4, !loadState(4));
         digitalWrite(RELAY_4, loadState(4)?RELAY_ON:RELAY_OFF);
         send(msg4.set(loadState(4)));
         }
  }
//--------------Roleta w jadalni duże okno------------------------
  if (debouncer5.update()) {
    int value5 = debouncer5.read();
    if((value5 == LOW && (digitalRead(RELAY_6) == RELAY_OFF))){
         saveState(5, !loadState(5));
         digitalWrite(RELAY_5, loadState(5)?RELAY_ON:RELAY_OFF);
         send(msg5.set(loadState(5)));
         }
  }
  if (debouncer6.update()) {
      int value6 = debouncer6.read();
    if((value6 == LOW) && (digitalRead(RELAY_5) == RELAY_OFF)){
         saveState(6, !loadState(6));
         digitalWrite(RELAY_6, loadState(6)?RELAY_ON:RELAY_OFF);
         send(msg6.set(loadState(6)));
         }
  }
//--------------Roleta w jadalni małe okno------------------------
  if (debouncer7.update()) {
    int value7 = debouncer7.read();
    if((value7 == LOW) && (digitalRead(RELAY_8) == RELAY_OFF)){
         saveState(7, !loadState(7));
         digitalWrite(RELAY_7, loadState(7)?RELAY_ON:RELAY_OFF);
         send(msg7.set(loadState(7)));
         }
  }
  if (debouncer8.update()) {
      int value8 = debouncer8.read();
    if((value8 == LOW) && (digitalRead(RELAY_7) == RELAY_OFF)){
         saveState(8, !loadState(8));
         digitalWrite(RELAY_8, loadState(8)?RELAY_ON:RELAY_OFF);
         send(msg8.set(loadState(8)));
         }
  }
//--------------Roleta w dużym pokoju duże okno od frontu---------
  if (debouncer9.update()) {
    int value9 = debouncer9.read();
    if((value9 == LOW) && (digitalRead(RELAY_10) == RELAY_OFF)){
         saveState(9, !loadState(9));
         digitalWrite(RELAY_9, loadState(9)?RELAY_ON:RELAY_OFF);
         send(msg9.set(loadState(9)));
         }
  }
  if (debouncer10.update()) {
      int value10 = debouncer10.read();
    if((value10 == LOW) && (digitalRead(RELAY_9) == RELAY_OFF)){
         saveState(10, !loadState(10));
         digitalWrite(RELAY_10, loadState(10)?RELAY_ON:RELAY_OFF);
         send(msg10.set(loadState(10)));
         }
  }
//--------------Roleta w dużym pokoju małe okno od frontu---------
  if (debouncer11.update()) {
    int value11 = debouncer11.read();
    if((value11 == LOW) && (digitalRead(RELAY_12) == RELAY_OFF)){
         saveState(11, !loadState(11));
         digitalWrite(RELAY_11, loadState(11)?RELAY_ON:RELAY_OFF);
         send(msg11.set(loadState(11)));
         }
  }
  if (debouncer12.update()) {
      int value12 = debouncer12.read();
    if((value12 == LOW) && (digitalRead(RELAY_11) == RELAY_OFF)){
         saveState(12, !loadState(12));
         digitalWrite(RELAY_12, loadState(12)?RELAY_ON:RELAY_OFF);
         send(msg12.set(loadState(12)));
         }
  }
//--------------Roleta w dużym pokoju małe okno od strony ogrodu--
  if (debouncer13.update()) {
    int value13 = debouncer13.read();
    if((value13 == LOW) && (digitalRead(RELAY_14) == RELAY_OFF)){
         saveState(13, !loadState(13));
         digitalWrite(RELAY_13, loadState(13)?RELAY_ON:RELAY_OFF);
         send(msg13.set(loadState(13)));
         }
  }
  if (debouncer14.update()) {
      int value14 = debouncer14.read();
    if((value14 == LOW) && (digitalRead(RELAY_13) == RELAY_OFF)){
         saveState(14, !loadState(14));
         digitalWrite(RELAY_14, loadState(14)?RELAY_ON:RELAY_OFF);
         send(msg14.set(loadState(14)));
         }
  }
//--------------Roleta w dużym pokoju drzwi tarasowe--------------
  if (debouncer15.update()) {
    int value15 = debouncer15.read();
    if((value15 == LOW) && (digitalRead(RELAY_16) == RELAY_OFF)){
         saveState(15, !loadState(15));
         digitalWrite(RELAY_15, loadState(15)?RELAY_ON:RELAY_OFF);
         send(msg15.set(loadState(15)));
         }
  }
  if (debouncer16.update()) {
      int value16 = debouncer16.read();
    if((value16 == LOW) && (digitalRead(RELAY_15) == RELAY_OFF)){
         saveState(16, !loadState(16));
         digitalWrite(RELAY_16, loadState(16)?RELAY_ON:RELAY_OFF);
         send(msg16.set(loadState(16)));
         }
  }
//--------------Roleta w gabinecie drzwi tarasowe-----------------
  if (debouncer17.update()) {
    int value17 = debouncer17.read();
    if((value17 == LOW) && (digitalRead(RELAY_18) == RELAY_OFF)){
         saveState(17, !loadState(17));
         digitalWrite(RELAY_17, loadState(17)?RELAY_ON:RELAY_OFF);
         send(msg17.set(loadState(17)));
         }
  }
  if (debouncer18.update()) {
      int value18 = debouncer18.read();
    if((value18 == LOW) && (digitalRead(RELAY_17) == RELAY_OFF)){
         saveState(18, !loadState(18));
         digitalWrite(RELAY_18, loadState(18)?RELAY_ON:RELAY_OFF);
         send(msg18.set(loadState(18)));
         }
  }
//--------------Roleta w gabinecie okno---------------------------
  if (debouncer19.update()) {
    int value19 = debouncer19.read();
    if((value19 == LOW) && (digitalRead(RELAY_20) == RELAY_OFF)){
         saveState(19, !loadState(19));
         digitalWrite(RELAY_19, loadState(19)?RELAY_ON:RELAY_OFF);
         send(msg19.set(loadState(19)));
         }
  }
  if (debouncer20.update()) {
      int value20 = debouncer20.read();
    if((value20 == LOW) && (digitalRead(RELAY_19) == RELAY_OFF)){
         saveState(20, !loadState(20));
         digitalWrite(RELAY_20, loadState(20)?RELAY_ON:RELAY_OFF);
         send(msg20.set(loadState(20)));
         }
  }
//--------------Roleta w łazience na parterze---------------------
  if (debouncer21.update()) {
    int value21 = debouncer21.read();
    if((value21 == LOW) && (digitalRead(RELAY_22) == RELAY_OFF)){
         saveState(21, !loadState(21));
         digitalWrite(RELAY_21, loadState(21)?RELAY_ON:RELAY_OFF);
         send(msg21.set(loadState(21)));
         }
  }
  if (debouncer22.update()) {
      int value22 = debouncer22.read();
    if((value22 == LOW) && (digitalRead(RELAY_21) == RELAY_OFF)){
         saveState(22, !loadState(22));
         digitalWrite(RELAY_22, loadState(22)?RELAY_ON:RELAY_OFF);
         send(msg22.set(loadState(22)));
         }
  }
//--------------Roleta w pomieszczeniu gospodarczym---------------
  if (debouncer23.update()) {
    int value23 = debouncer23.read();
    if((value23 == LOW) && (digitalRead(RELAY_24) == RELAY_OFF)){
         saveState(23, !loadState(23));
         digitalWrite(RELAY_23, loadState(23)?RELAY_ON:RELAY_OFF);
         send(msg23.set(loadState(23)));
         }
  }
  if (debouncer24.update()) {
      int value24 = debouncer24.read();
    if((value24 == LOW) && (digitalRead(RELAY_23) == RELAY_OFF)){
         saveState(24, !loadState(24));
         digitalWrite(RELAY_24, loadState(24)?RELAY_ON:RELAY_OFF);
         send(msg24.set(loadState(24)));
         }
  }
//--------------Roleta w garażu-----------------------------------
  if (debouncer25.update()) {
    int value25 = debouncer25.read();
    if((value25 == LOW) && (digitalRead(RELAY_26) == RELAY_OFF)){
         saveState(25, !loadState(25));
         digitalWrite(RELAY_25, loadState(25)?RELAY_ON:RELAY_OFF);
         send(msg25.set(loadState(25)));
         }
  }
  if (debouncer26.update()) {
      int value26 = debouncer26.read();
    if((value26 == LOW) && (digitalRead(RELAY_25) == RELAY_OFF)){
         saveState(26, !loadState(26));
         digitalWrite(RELAY_26, loadState(26)?RELAY_ON:RELAY_OFF);
         send(msg26.set(loadState(26)));
         }
  }
//--------------Brama garażowa------------------------------------
    if (debouncer27.update()) {
    int value27 = debouncer27.read();
    if((value27 == LOW) && (digitalRead(RELAY_28) == RELAY_OFF)){
         saveState(27, !loadState(27));
         digitalWrite(RELAY_27, loadState(27)?RELAY_ON:RELAY_OFF);
         send(msg27.set(loadState(27)));
         }
  }
  if (debouncer28.update()) {
      int value28 = debouncer28.read();
    if((value28 == LOW) && (digitalRead(RELAY_27) == RELAY_OFF)){
         saveState(28, !loadState(28));
         digitalWrite(RELAY_28, loadState(28)?RELAY_ON:RELAY_OFF);
         send(msg28.set(loadState(28)));
         }
  }
}

void receive(const MyMessage &message) {
  
//--------------Roleta w kuchni duże okno-------------------------
  {
  if (message.sensor == ROLETA_1_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_1, HIGH);
    digitalWrite(RELAY_2, LOW);
  }
  }
  if (message.sensor == ROLETA_1_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_1, LOW);
    digitalWrite(RELAY_2, LOW);
  }
  }
  if (message.sensor == ROLETA_1_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_2, HIGH);
    digitalWrite(RELAY_1, LOW);
  }
  }
  }
  {
    
//--------------Roleta w kuchni małe okno-------------------------
    
  if (message.sensor == ROLETA_2_CHILD){
  if (message.type == V_UP) {
    digitalWrite(RELAY_3, HIGH);
    digitalWrite(RELAY_4, LOW);
  }
  }
  if (message.sensor == ROLETA_2_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_3, LOW);
    digitalWrite(RELAY_4, LOW);
  }
  }
  if (message.sensor == ROLETA_2_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_4, HIGH);
    digitalWrite(RELAY_3, LOW);
  }
  }
  }
//--------------Roleta w jadalni duże okno------------------------
  {
  if (message.sensor == ROLETA_3_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_5, HIGH);
    digitalWrite(RELAY_6, LOW);
  }
  }
  if (message.sensor == ROLETA_3_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_5, LOW);
    digitalWrite(RELAY_6, LOW);
  }
  }
  if (message.sensor == ROLETA_3_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_6, HIGH);
    digitalWrite(RELAY_5, LOW);
  }
  }
  }
 
//--------------Roleta w jadalni małe okno------------------------
  {
  if (message.sensor == ROLETA_4_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_7, HIGH);
    digitalWrite(RELAY_8, LOW);
  }
  }
  if (message.sensor == ROLETA_4_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_7, LOW);
    digitalWrite(RELAY_8, LOW);
  }
  }
  if (message.sensor == ROLETA_4_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_8, HIGH);
    digitalWrite(RELAY_7, LOW);
  }
  }
  }
  
//--------------Roleta w dużym pokoju duże okno od frontu---------
  {
  if (message.sensor == ROLETA_5_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_9, HIGH);
    digitalWrite(RELAY_10, LOW);
  }
  }
  if (message.sensor == ROLETA_5_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_9, LOW);
    digitalWrite(RELAY_10, LOW);
  }
  }
  if (message.sensor == ROLETA_5_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_10, HIGH);
    digitalWrite(RELAY_9, LOW);
  }
  }
  }
 
//--------------Roleta w dużym pokoju małe okno od frontu---------
  {
  if (message.sensor == ROLETA_6_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_11, HIGH);
    digitalWrite(RELAY_12, LOW);
  }
  }
  if (message.sensor == ROLETA_6_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_11, LOW);
    digitalWrite(RELAY_12, LOW);
  }
  }
  if (message.sensor == ROLETA_6_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_12, HIGH);
    digitalWrite(RELAY_11, LOW);
  }
  }
  }
  
//--------------Roleta w dużym pokoju małe okno od strony ogrodu--
  {
  if (message.sensor == ROLETA_7_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_13, HIGH);
    digitalWrite(RELAY_14, LOW);
  }
  }
  if (message.sensor == ROLETA_7_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_13, LOW);
    digitalWrite(RELAY_14, LOW);
  }
  }
  if (message.sensor == ROLETA_7_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_14, HIGH);
    digitalWrite(RELAY_13, LOW);
  }
  }
  }
  
//--------------Roleta w dużym pokoju drzwi tarasowe--------------
  {
  if (message.sensor == ROLETA_8_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_15, HIGH);
    digitalWrite(RELAY_16, LOW);
  }
  }
  if (message.sensor == ROLETA_8_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_15, LOW);
    digitalWrite(RELAY_16, LOW);
  }
  }
  if (message.sensor == ROLETA_8_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_16, HIGH);
    digitalWrite(RELAY_15, LOW);
  }
  }
  }

//--------------Roleta w gabinecie drzwi tarasowe-----------------
  {
  if (message.sensor == ROLETA_9_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_17, HIGH);
    digitalWrite(RELAY_18, LOW);
  }
  }
  if (message.sensor == ROLETA_9_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_17, LOW);
    digitalWrite(RELAY_18, LOW);
  }
  }
  if (message.sensor == ROLETA_9_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_18, HIGH);
    digitalWrite(RELAY_17, LOW);
  }
  }
  }
  
//--------------Roleta w gabinecie okno---------------------------
  {
  if (message.sensor == ROLETA_10_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_19, HIGH);
    digitalWrite(RELAY_20, LOW);
  }
  }
  if (message.sensor == ROLETA_10_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_19, LOW);
    digitalWrite(RELAY_20, LOW);
  }
  }
  if (message.sensor == ROLETA_10_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_20, HIGH);
    digitalWrite(RELAY_19, LOW);
  }
  }
  }
  
//--------------Roleta w łazience na parterze---------------------
  {
  if (message.sensor == ROLETA_11_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_21, HIGH);
    digitalWrite(RELAY_22, LOW);
  }
  }
  if (message.sensor == ROLETA_11_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_21, LOW);
    digitalWrite(RELAY_22, LOW);
  }
  }
  if (message.sensor == ROLETA_11_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_22, HIGH);
    digitalWrite(RELAY_21, LOW);
  }
  }
  }
  {
//--------------Roleta w pomieszczeniu gospodarczym---------------
  if (message.sensor == ROLETA_12_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_23, HIGH);
    digitalWrite(RELAY_24, LOW);
  }
  }
  if (message.sensor == ROLETA_12_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_23, LOW);
    digitalWrite(RELAY_24, LOW);
  }
  }
  if (message.sensor == ROLETA_12_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_24, HIGH);
    digitalWrite(RELAY_23, LOW);
  }
  }
  }
//--------------Roleta w garażu-----------------------------------
  {
  if (message.sensor == ROLETA_13_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_25, HIGH);
    digitalWrite(RELAY_26, LOW);
  }
  }
  if (message.sensor == ROLETA_13_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_25, LOW);
    digitalWrite(RELAY_26, LOW);
  }
  }
  if (message.sensor == ROLETA_13_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_26, HIGH);
    digitalWrite(RELAY_25, LOW);
  }
  }
  }
 
//--------------Brama garażowa------------------------------------
    {
  if (message.sensor == ROLETA_14_CHILD){ 
     if (message.type == V_UP) {
    digitalWrite(RELAY_27, HIGH);
    digitalWrite(RELAY_28, LOW);
  }
  }
  if (message.sensor == ROLETA_14_CHILD){
  if (message.type == V_STOP ) {
    digitalWrite(RELAY_27, LOW);
    digitalWrite(RELAY_28, LOW);
  }
  }
  if (message.sensor == ROLETA_14_CHILD){
  if (message.type == V_DOWN) {
    digitalWrite(RELAY_28, HIGH);
    digitalWrite(RELAY_27, LOW);
  }
  }
    }
}
  

 
 
 
Dodane : 29/01/2022 11:14 am
Udostępnij: