Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. help about simple roller shutter sketch

help about simple roller shutter sketch

Scheduled Pinned Locked Moved Development
1 Posts 1 Posters 901 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reza
    wrote on last edited by
    #1

    hi
    i use this sketch for roller shutter with button.
    i want when connection is fail so button work lonely ! and when push button if connection is ok a message send to controller and in domoticz i see open or close or stop.if connection is fail (or not) after 2 hours send a message to controller from state of Blind.

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_RF24_CHANNEL 0
    #define MY_REPEATER_FEATURE
    #define MY_NODE_ID 11
    #define MY_TRANSPORT_WAIT_READY_MS 10000
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    #define RELAY_ON 0
    #define RELAY_OFF 1
    
    #define CHILD_ID 1
    
    const int buttonPinA = 14;
    const int buttonPinB = 15;
    const int buttonPinC = 16;
    const int relayPinA = 3;
    const int relayPinB = 4;
    int oldValueA = 0;
    int oldValueB = 0;
    int oldValueC = 0;
    bool stateA = false;
    bool stateB = false;
    bool stateC = false;
    int trigger = 0;
    
    unsigned long time_m;
    unsigned long a;
    
    Bounce debouncerA = Bounce();
    Bounce debouncerB = Bounce();
    Bounce debouncerC = Bounce();
    
    MyMessage msg(CHILD_ID, V_PERCENTAGE);
    
    void setup() {
      pinMode(buttonPinA, INPUT_PULLUP);
      pinMode(buttonPinB, INPUT_PULLUP);
      pinMode(buttonPinC, INPUT_PULLUP);
      pinMode(relayPinA, OUTPUT);
      pinMode(relayPinB, OUTPUT);
      debouncerA.attach(buttonPinA);
      debouncerA.interval(5);
      debouncerB.attach(buttonPinB);
      debouncerB.interval(5);
      debouncerC.attach(buttonPinC);
      debouncerC.interval(5);
      digitalWrite(relayPinA, RELAY_OFF);
      digitalWrite(relayPinB, RELAY_OFF);
      oldValueA = digitalRead(buttonPinA);
      oldValueB = digitalRead(buttonPinB);
      oldValueC = digitalRead(buttonPinC);
    }
    
    void presentation()
    {
      sendSketchInfo("Roller shutter", "1.0");
      present(CHILD_ID, S_COVER);
    }
    
    void loop() {
      {
        time_m = millis();
        a = time_m % 7200000;
        if (a == 0) {
          send(msg.set(stateA));
          send(msg.set(stateB));
          send(msg.set(stateC));
        }
      }
      {
        debouncerA.update();
        // Get the update value
        int valueA = debouncerA.read();
        if (valueA != oldValueA) {
          stateA =  !stateA;
          send(msg.set(stateA),false);
          digitalWrite(relayPinA, HIGH);
          delay(500);
          digitalWrite(relayPinB, LOW);
          oldValueA = valueA;
        }
    
    
        debouncerB.update();
        // Get the update value
        int valueB = debouncerB.read();
        if (valueB != oldValueB) {
          stateB =  !stateB;
          send(msg.set(stateB),false);
          digitalWrite(relayPinA, HIGH);
          delay(500);
          digitalWrite(relayPinB, HIGH);
          oldValueB = valueB;
        }
        debouncerC.update();
        // Get the update value
        int valueC = debouncerC.read();
        if (valueC != oldValueC) {
          stateC =  !stateC;
          send(msg.set(stateC),false);
          digitalWrite(relayPinB, HIGH);
          delay(500);
          digitalWrite(relayPinA, LOW);
          oldValueC = valueC;
        }
      }
    }
    void receive(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type == V_UP) {
            stateA = message.getBool();
            digitalWrite(relayPinA, HIGH);
            delay(500);
            digitalWrite(relayPinB, LOW);
      }
       if (message.type == V_STOP ){
            stateB = message.getBool();
            digitalWrite(relayPinA, HIGH);
            delay(500);
            digitalWrite(relayPinB, HIGH);
       }
         if (message.type == V_DOWN){
            stateC = message.getBool();
            digitalWrite(relayPinB, HIGH);
            delay(500);
            digitalWrite(relayPinA, LOW);
        }
        // Write some debug info
        Serial.print("Incoming change for sensor:");
        Serial.println(message.sensor);
        Serial.print("from node:");
        Serial.println(message.sender);
        Serial.print(", New status: ");
        Serial.println(message.getBool());
      }
    
    

    what do change in my sketch ? thank you

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    11

    Online

    12.0k

    Users

    11.2k

    Topics

    113.4k

    Posts


    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • MySensors
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular