Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Help with 595

  1. #1
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    82

    Help with 595

    Hey everyone,
    I'm trying to setup a power board that has switched outlets controlled via relays over the network.

    So far I have got the web server working but can't workout how to control the 595's the way I would like to.

    On the web server I have a on and off button for each relay.

    I have run the test led test on the 595 tutorial and it works.

    Want I can not work out is how to set a bit in the byte to a 1 or 0.

    So if I hit on for relay 1 it turns on
    Hit on for relay 7 it then turns on as well and 1 staying on.
    If I was to hit on for relay 1 again it will stay on.
    And if I hit off for relay 7 it turns off but relay 1 stays on

    Hope all that makes sense

    If anyone can point me to the right tutorial or the bit of code that will work for me will be amazing!!!

    Thanks everyone 😊

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,356
    Can you link to the 595 tutorial, or post the code here directly please. If the question is about how to set single bits in a byte normal method is the AND & or OR | commands with a number containing the bit you need (bitmask) and the byte you want to manipulate.

    https://www.arduino.cc/en/Reference/BitwiseAnd

    So normal method to set a the second bit of relayByte would be
    relayByte= relayByte|b00000010;

    to clear it you can
    relayByte= relayByte&b11111101;

  3. #3
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    82
    the code i have at the moment is. will try GremlinWrangler help this afternoon when i have the project with me.


    Code:
    /* 485 serial1 pins 0&1 transmitter enable as pin 14
       network pins 9-13
       garage buttons 21-23
       dmx pin 20
       power point control 4-6
    */
    #include <SPI.h>
    #include <Ethernet.h>
    #include <DmxSimple.h>
    
    byte mac[] = { 0x04, 0xE9, 0xE5, 0x01, 0x05, 0x2D };
    byte ip[] = { 192, 168, 0, 17 };
    byte gateway[] = { 192, 168, 0, 1 };
    byte subnet[] = { 255, 255, 255, 192 };
    EthernetServer server(80);
    
    const byte gd = 21;
    const byte gs = 22;
    const byte gu = 23;
    
    const byte dmx = 20;
    const byte reciverA = 19;        // to control mux's doing input
    const byte reciverB = 18;
    const byte reciverC = 17;
    const byte read1 = 2;
    const byte read2 = 3;
    const byte latchPin = 5;
    const byte clockPin = 4;
    const byte dataPin = 6;
    
    byte data1;
    byte data2;
    byte switch1[8] = {0b00000000};
    byte switch2[8] = {0b00000000};
    
    String readString;
    
    void setup() {
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW);
      pinMode(10, OUTPUT);
      digitalWrite(10, HIGH);
      pinMode(latchPin, OUTPUT);
      digitalWrite(latchPin, HIGH);
      digitalWrite(9, HIGH);
      Ethernet.begin(mac, ip, gateway, subnet);
      server.begin();
      Serial.begin(9600);
      Serial1.begin(2400);
      Serial1.transmitterEnable(14);
      DmxSimple.usePin(20);
      pinMode(gd, OUTPUT);
      pinMode(gs, OUTPUT);
      pinMode(gu, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
    
      digitalWrite(gd, LOW);
      digitalWrite(gs, LOW);
      digitalWrite(gu, LOW);
      Serial.print("server is at ");
      Serial.println(Ethernet.localIP());
    
    
    }
    
    void loop() {
      EthernetClient client = server.available();
      if (client) {
        while (client.connected()) {
          if (client.available()) {
            char c = client.read();
    
            if (readString.length() < 100) {
              readString += c;
              Serial.print(c);
            }
            if (c == '\n') {
    
              client.println("HTTP/1.1 200 OK");
              client.println("Content-Type: text/html");
              client.println("Server: Nick's Home automation");
              client.println();
    
              client.println("<html>");
              client.println("<HEAD>");
              client.println("<TITLE>Nick's home automation</TITLE>");
              client.println("</HEAD>");
              client.println("<BODY>");
              client.println("<h3> Garage Door</h3>");
              client.println("<p>");
              client.println("<a href=\"/?0\">Open</a>");
              client.println("<a href=\"/?1\">Stop</a>");
              client.println("<a href=\"/?2\">Down</a>");
              client.println("</p>");
              client.println("<h3>Blinds</h3>");
              client.println("<h5>Master Bed Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?3\">Left Open</a>");
              client.println("<a href=\"/?4\">Left Stop</a>");
              client.println("<a href=\"/?5\">Left Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?6\">Right Open</a>");
              client.println("<a href=\"/?7\">Right Stop</a>");
              client.println("<a href=\"/?8\">Right Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?9\">Over Open</a>");
              client.println("<a href=\"/?a\">Over Stop</a>");
              client.println("<a href=\"/?b\">Over Down</a>");
              client.println("</p>");
              client.println("<h5>Media Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?c\">Open</a>");
              client.println("<a href=\"/?d\">Stop</a>");
              client.println("<a href=\"/?e\">Down</a>");
              client.println("</p>");
              client.println("<h5>GYM</h5>");
              client.println("<p>");
              client.println("<a href=\"/?f\">Open</a>");
              client.println("<a href=\"/?g\">Stop</a>");
              client.println("<a href=\"/?h\">Down</a>");
              client.println("</p>");
              client.println("<h5>Spare Bed</h5>");
              client.println("<p>");
              client.println("<a href=\"/?i\">Open </a>");
              client.println("<a href=\"/?j\">Stop</a>");
              client.println("<a href=\"/?k\">Down</a>");
              client.println("</p>");
              client.println("<h5>Lounge Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?l\">Left Open</a>");
              client.println("<a href=\"/?m\">Left Stop</a>");
              client.println("<a href=\"/?n\">Left Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?o\">Mid Open</a>");
              client.println("<a href=\"/?p\">Mid Stop</a>");
              client.println("<a href=\"/?q\">Mid Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?r\">Right Open</a>");
              client.println("<a href=\"/?s\">Right Stop</a>");
              client.println("<a href=\"/?t\">Right Down</a>");
              client.println("</p>");
              client.println("<h5>Kitchen</h5>");
              client.println("<p>");
              client.println("<a href=\"/?u\">Open</a>");
              client.println("<a href=\"/?v\">Stop</a>");
              client.println("<a href=\"/?w\">Down</a>");
              client.println("</p>");
              client.println("<h5>Workroom</h5>");
              client.println("<p>");
              client.println("<a href=\"/?x\">Open</a>");
              client.println("<a href=\"/?y\">Stop</a>");
              client.println("<a href=\"/?z\">Down</a>");
              client.println("</p>");
              client.println("<h3>Power</3>");
              client.println("<h5>");
              client.println("</h5>");
              client.println("<p>");
              client.println("<a href=\"/?L\">1 On</a>");
              client.println("<a href=\"/?M\">1 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?N\">2 On</a>");
              client.println("<a href=\"/?O\">2 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?P\">3 On</a>");
              client.println("<a href=\"/?Q\">3 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?R\">4 On</a>");
              client.println("<a href=\"/?S\">4 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?T\">5 On</a>");
              client.println("<a href=\"/?U\">5 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?V\">6 On</a>");
              client.println("<a href=\"/?W\">6 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?X\">7 On</a>");
              client.println("<a href=\"/?Y\">7 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?Z\">8 On</a>");
              client.println("<a href=\"/?aa\">8 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?bb\">9 On</a>");
              client.println("<a href=\"/?cc\">9 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?dd\">10 On</a>");
              client.println("<a href=\"/?ee\">10 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?ff\">11 On</a>");
              client.println("<a href=\"/?gg\">11 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?hh\">12 On</a>");
              client.println("<a href=\"/?ii\">12 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?jj\">13 On</a>");
              client.println("<a href=\"/?kk\">13 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?ll\">14 On</a>");
              client.println("<a href=\"/?mm\">14 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?nn\">15 On</a>");
              client.println("<a href=\"/?oo\">15 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?pp\">16 On</a>");
              client.println("<a href=\"/?qq\">16 Off</a>");
              client.println("</p>");
              client.println("<h4>Pairing Blinds</h4>");
              client.println("<p>");
              client.println("<a href=\"/?A\">Bed Left</a>");
              client.println("<a href=\"/?B\">Bed Right</a>");
              client.println("<a href=\"/?C\">Bed Over</a>");
              client.println("<a href=\"/?D\">Media</a>");
              client.println("<a href=\"/?E\">Gym</a>");
              client.println("<a href=\"/?F\">Bed 2</a>");
              client.println("<a href=\"/?G\">Door Left</a>");
              client.println("<a href=\"/?H\">Door Mid</a>");
              client.println("<a href=\"/?I\">Door Right</a>");
              client.println("<a href=\"/?J\">Kitchen</a>");
              client.println("<a href=\"/?K\">Workroom</a>");
              client.println("</p>");
              client.println("</BODY>");
              client.println("</html>");
    
              delay(2);
              client.stop();
    
              if (readString.indexOf("/?0") > 0) {          //garage open (pin)
                digitalWrite(gu, HIGH);
                delay(50);
                digitalWrite(gu, LOW);
              }
    
              if (readString.indexOf("/?1") > 0) {          //garage stop (pin)
                digitalWrite(gs, HIGH);
                delay(50);
                digitalWrite(gs, LOW);
              }
    
              if (readString.indexOf("/?2") > 0) {          //garage down (pin)
                digitalWrite(gd, HIGH);
                delay(50);
                digitalWrite(gd, LOW);
              }
    
              if (readString.indexOf("/?3") > 0) {          //master bed blind left open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xce);
              }
    
              if (readString.indexOf("/?4") > 0) {          //master bed blind left stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xdf);
              }
    
              if (readString.indexOf("/?5") > 0) {          //master bed blind left down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xfd);
              }
    
              if (readString.indexOf("/?6") > 0) {          //master bed blind right open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xfe);
              }
    
              if (readString.indexOf("/?7") > 0) {          //master bed blind right stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xef);
              }
    
              if (readString.indexOf("/?8") > 0) {          //master bed blind right down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xcd);
              }
    
              if (readString.indexOf("/?9") > 0) {          //master bed blind over open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xee);
              }
    
              if (readString.indexOf("/?a") > 0) {          //master bed blind over stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xff);
              }
    
              if (readString.indexOf("/?b") > 0) {          //master bed blind over down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xdd);
              }
    
              if (readString.indexOf("/?c") > 0) {          //media room blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x9e);
              }
    
              if (readString.indexOf("/?d") > 0) {          //media room blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x8f);
              }
    
              if (readString.indexOf("/?e") > 0) {          //media room blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xad);
              }
              if (readString.indexOf("/?f") > 0) {          //gym blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x8e);
              }
    
              if (readString.indexOf("/?g") > 0) {          //gym blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x9f);
              }
    
              if (readString.indexOf("/?h") > 0) {          //gym blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xbd);
              }
    
              if (readString.indexOf("/?i") > 0) {          //bed 2 blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xbe);
              }
    
              if (readString.indexOf("/?j") > 0) {          //bed 2 blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xaf);
              }
    
              if (readString.indexOf("/?k") > 0) {          //bed 2 blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x8d);
              }
    
              if (readString.indexOf("/?l") > 0) {          //door blind left open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xae);
              }
    
              if (readString.indexOf("/?m") > 0) {          //door blind left stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xbf);
              }
    
              if (readString.indexOf("/?n") > 0) {          //door blind left down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x9d);
              }
    
              if (readString.indexOf("/?o") > 0) {          //door blind mid open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x5e);
              }
    
              if (readString.indexOf("/?p") > 0) {          //door blind mid stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x4f);
              }
    
              if (readString.indexOf("/?q") > 0) {          //door blind mid down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x6d);
              }
              if (readString.indexOf("/?r") > 0) {          //door blind right open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x4e);
              }
    
              if (readString.indexOf("/?s") > 0) {          //door blind right stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x5f);
              }
    
              if (readString.indexOf("/?t") > 0) {          //door blind right down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x7d);
              }
    
              if (readString.indexOf("/?u") > 0) {          //kitchen open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x7e);
              }
    
              if (readString.indexOf("/?v") > 0) {          //kitchen stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x6f);
              }
    
              if (readString.indexOf("/?w") > 0) {          //kitchen down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x4d);
              }
    
              if (readString.indexOf("/?x") > 0) {          //workroom open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x6e);
              }
    
              if (readString.indexOf("/?y") > 0) {          //workroom stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x7f);
              }
    
              if (readString.indexOf("/?z") > 0) {          //workroom down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x5d);
              }
    
              if (readString.indexOf("/?A") > 0) {          //master bed left pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xb9);
              }
    
              if (readString.indexOf("/?B") > 0) {          //master bed right pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x89);
              }
    
              if (readString.indexOf("/?C") > 0) {          //master bed over pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x99);
              }
    
              if (readString.indexOf("/?D") > 0) {          //media room pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xe9);
              }
    
              if (readString.indexOf("/?E") > 0) {          //gym pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xf9);
              }
    
              if (readString.indexOf("/?F") > 0) {          //bed 2 pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xc9);
              }
    
              if (readString.indexOf("/?G") > 0) {          //door left pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xd9);
              }
    
              if (readString.indexOf("/?H") > 0) {          //door mid pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x29);
              }
    
              if (readString.indexOf("/?I") > 0) {          //door right pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x39);
              }
    
              if (readString.indexOf("/?J") > 0) {          //kitchen pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x09);
              }
    
              if (readString.indexOf("/?K") > 0) {          //workroom pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x19);
              }
    
              if (readString.indexOf("/?L") > 0) {    // reley 595 1 on
              }
    
              if (readString.indexOf("/?M") > 0) {    // reley 595 1 off
              }
    
              if (readString.indexOf("/?N") > 0) {    // reley 595 2 on
              }
    
              if (readString.indexOf("/?O") > 0) {    // reley 595 2 off
              }
    
              if (readString.indexOf("/?P") > 0) {    // reley 595 3 on
              }
    
              if (readString.indexOf("/?Q") > 0) {    // reley 595 3 off
              }
    
              if (readString.indexOf("/?R") > 0) {    // reley 595 4 on
              }
    
              if (readString.indexOf("/?S") > 0) {    // reley 595 4 off
              }
    
              if (readString.indexOf("/?T") > 0) {    // reley 595 5 on
              }
    
              if (readString.indexOf("/?U") > 0) {    // reley 595 5 off
              }
    
              if (readString.indexOf("/?V") > 0) {    // reley 595 6 on
              }
    
              if (readString.indexOf("/?W") > 0) {    // reley 595 6 off
              }
    
              if (readString.indexOf("/?X") > 0) {    // reley 595 7 on
              }
    
              if (readString.indexOf("/?Y") > 0) {    // reley 595 7 off
              }
    
              if (readString.indexOf("/?Z") > 0) {    // reley 595 8 on
              }
    
              if (readString.indexOf("/?aa") > 0) {    // reley 595 8 off
              }
    
              if (readString.indexOf("/?bb") > 0) {    // reley 595 9 on
              }
    
              if (readString.indexOf("/?cc") > 0) {    // reley 595 9 off
              }
    
              if (readString.indexOf("/?dd") > 0) {    // reley 595 10 on
              }
    
              if (readString.indexOf("/?ee") > 0) {    // reley 595 10 off
              }
    
              if (readString.indexOf("/?ff") > 0) {    // reley 595 11 on
              }
    
              if (readString.indexOf("/?gg") > 0) {    // reley 595 11 off
              }
              
              if (readString.indexOf("/?hh") > 0) {    // reley 595 12 on
              }
    
              if (readString.indexOf("/?ii") > 0) {    // reley 595 12 off
              }
              
              if (readString.indexOf("/?jj") > 0) {    // reley 595 13 on
              }
    
              if (readString.indexOf("/?kk") > 0) {    // reley 595 13 off
              }
              
              if (readString.indexOf("/?ll") > 0) {    // reley 595 14 on
              }
    
              if (readString.indexOf("/?mm") > 0) {    // reley 595 14 off
              }
              
              if (readString.indexOf("/?nn") > 0) {    // reley 595 15 on
              }
    
              if (readString.indexOf("/?oo") > 0) {    // reley 595 15 off
              }
              
              if (readString.indexOf("/?pp") > 0) {    // reley 595 16 on
              }
    
              if (readString.indexOf("/?qq") > 0) {    // reley 595 16 off
              }
              readString = "";
            }
          }
        }
      }
      for (int j = 0; j < 8; j++){
        data1 = switch1[j];
        data2 = switch2[j];
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, data2);
        shiftOut(dataPin, clockPin, data1);
        digitalWrite(latchPin, HIGH);
        delay(100);
        
      }
    }
    void shiftOut(int myDataPin, int myClockPin, byte myDataOut){
      int i=0;
      int pinState;
      pinMode(myClockPin, OUTPUT);
      pinMode(myDataPin, OUTPUT);
      digitalWrite(myDataPin, LOW);
      digitalWrite(myClockPin, LOW);
    
      for (i=7; i>=0; i--){
        digitalWrite(myClockPin, LOW);
        if (myDataOut & (1<<i)){
          pinState=1;
        }
        else{
          pinState=0;
        }
        digitalWrite(myDataPin, pinState);
        digitalWrite(myClockPin, HIGH);
        digitalWrite(myDataPin, LOW);
      }
      digitalWrite(myClockPin, LOW);
      
    }

  4. #4
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    82
    thank you GremlinWrangler for you help!!! works like a dream now
    Code:
    /* 485 serial1 pins 0&1 transmitter enable as pin 14
       network pins 9-13
       garage buttons 21-23
       dmx pin 20
       power point control 4-6  */
    
    #include <SPI.h>
    #include <Ethernet.h>
    #include <DmxSimple.h>
    
    byte mac[] = { 0x04, 0xE9, 0xE5, 0x01, 0x05, 0x2D };
    byte ip[] = { 192, 168, 0, 17 };
    byte gateway[] = { 192, 168, 0, 1 };
    byte subnet[] = { 255, 255, 255, 192 };
    EthernetServer server(80);
    
    const byte read1 = 2;
    const byte read2 = 3;
    const byte clockPin = 4;
    const byte latchPin = 5;
    const byte dataPin = 6;
    const byte reciverC = 17;
    const byte reciverB = 18;
    const byte reciverA = 19;
    const byte dmx = 20;
    const byte gd = 21;
    const byte gs = 22;
    const byte gu = 23;
    
    byte relayByte1 = 0b00000000;
    byte relayByte2 = 0b00000000;
    
    String readString;
    
    void setup() {
      pinMode(9, OUTPUT);
      digitalWrite(9, LOW);
      pinMode(10, OUTPUT);
      digitalWrite(10, HIGH);
      pinMode(latchPin, OUTPUT);
      digitalWrite(latchPin, HIGH);
      digitalWrite(9, HIGH);
      Ethernet.begin(mac, ip, gateway, subnet);
      server.begin();
      Serial.begin(9600);
      Serial1.begin(2400);
      Serial1.transmitterEnable(14);
      DmxSimple.usePin(20);
      pinMode(gd, OUTPUT);
      pinMode(gs, OUTPUT);
      pinMode(gu, OUTPUT);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
    
      digitalWrite(gd, LOW);
      digitalWrite(gs, LOW);
      digitalWrite(gu, LOW);
      Serial.print("server is at ");
      Serial.println(Ethernet.localIP());
    }
    
    void loop() {
      EthernetClient client = server.available();
      if (client) {
        while (client.connected()) {
          if (client.available()) {
            char c = client.read();
    
            if (readString.length() < 100) {
              readString += c;
              Serial.print(c);
            }
            
            if (c == '\n') {
              client.println("HTTP/1.1 200 OK");
              client.println("Content-Type: text/html");
              client.println("Server: Nick's Home automation");
              client.println();
              
              client.println("<html>");
              client.println("<HEAD>");
              client.println("<TITLE>Nick's home automation</TITLE>");
              client.println("</HEAD>");
              client.println("<BODY>");
              client.println("<h3> Garage Door</h3>");
              client.println("<p>");
              client.println("<a href=\"/?0\">Open</a>");
              client.println("<a href=\"/?1\">Stop</a>");
              client.println("<a href=\"/?2\">Down</a>");
              client.println("</p>");
              client.println("<h3>Blinds</h3>");
              client.println("<h5>Master Bed Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?3\">Left Open</a>");
              client.println("<a href=\"/?4\">Left Stop</a>");
              client.println("<a href=\"/?5\">Left Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?6\">Right Open</a>");
              client.println("<a href=\"/?7\">Right Stop</a>");
              client.println("<a href=\"/?8\">Right Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?9\">Over Open</a>");
              client.println("<a href=\"/?a\">Over Stop</a>");
              client.println("<a href=\"/?b\">Over Down</a>");
              client.println("</p>");
              client.println("<h5>Media Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?c\">Open</a>");
              client.println("<a href=\"/?d\">Stop</a>");
              client.println("<a href=\"/?e\">Down</a>");
              client.println("</p>");
              client.println("<h5>GYM</h5>");
              client.println("<p>");
              client.println("<a href=\"/?f\">Open</a>");
              client.println("<a href=\"/?g\">Stop</a>");
              client.println("<a href=\"/?h\">Down</a>");
              client.println("</p>");
              client.println("<h5>Spare Bed</h5>");
              client.println("<p>");
              client.println("<a href=\"/?i\">Open </a>");
              client.println("<a href=\"/?j\">Stop</a>");
              client.println("<a href=\"/?k\">Down</a>");
              client.println("</p>");
              client.println("<h5>Lounge Room</h5>");
              client.println("<p>");
              client.println("<a href=\"/?l\">Left Open</a>");
              client.println("<a href=\"/?m\">Left Stop</a>");
              client.println("<a href=\"/?n\">Left Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?o\">Mid Open</a>");
              client.println("<a href=\"/?p\">Mid Stop</a>");
              client.println("<a href=\"/?q\">Mid Down</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?r\">Right Open</a>");
              client.println("<a href=\"/?s\">Right Stop</a>");
              client.println("<a href=\"/?t\">Right Down</a>");
              client.println("</p>");
              client.println("<h5>Kitchen</h5>");
              client.println("<p>");
              client.println("<a href=\"/?u\">Open</a>");
              client.println("<a href=\"/?v\">Stop</a>");
              client.println("<a href=\"/?w\">Down</a>");
              client.println("</p>");
              client.println("<h5>Workroom</h5>");
              client.println("<p>");
              client.println("<a href=\"/?x\">Open</a>");
              client.println("<a href=\"/?y\">Stop</a>");
              client.println("<a href=\"/?z\">Down</a>");
              client.println("</p>");
              client.println("<h3>Power</3>");
              client.println("<h5>");
              client.println("</h5>");
              client.println("<p>");
              client.println("<a href=\"/?L\">1 On</a>");
              client.println("<a href=\"/?M\">1 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?N\">2 On</a>");
              client.println("<a href=\"/?O\">2 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?P\">3 On</a>");
              client.println("<a href=\"/?Q\">3 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?R\">4 On</a>");
              client.println("<a href=\"/?S\">4 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?T\">5 On</a>");
              client.println("<a href=\"/?U\">5 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?V\">6 On</a>");
              client.println("<a href=\"/?W\">6 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?X\">7 On</a>");
              client.println("<a href=\"/?Y\">7 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?Z\">8 On</a>");
              client.println("<a href=\"/?aa\">8 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?bb\">9 On</a>");
              client.println("<a href=\"/?cc\">9 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?dd\">10 On</a>");
              client.println("<a href=\"/?ee\">10 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?ff\">11 On</a>");
              client.println("<a href=\"/?gg\">11 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?hh\">12 On</a>");
              client.println("<a href=\"/?ii\">12 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?jj\">13 On</a>");
              client.println("<a href=\"/?kk\">13 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?ll\">14 On</a>");
              client.println("<a href=\"/?mm\">14 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?nn\">15 On</a>");
              client.println("<a href=\"/?oo\">15 Off</a>");
              client.println("</p>");
              client.println("<p>");
              client.println("<a href=\"/?pp\">16 On</a>");
              client.println("<a href=\"/?qq\">16 Off</a>");
              client.println("</p>");
              client.println("<h4>Pairing Blinds</h4>");
              client.println("<p>");
              client.println("<a href=\"/?A\">Bed Left</a>");
              client.println("<a href=\"/?B\">Bed Right</a>");
              client.println("<a href=\"/?C\">Bed Over</a>");
              client.println("<a href=\"/?D\">Media</a>");
              client.println("<a href=\"/?E\">Gym</a>");
              client.println("<a href=\"/?F\">Bed 2</a>");
              client.println("<a href=\"/?G\">Door Left</a>");
              client.println("<a href=\"/?H\">Door Mid</a>");
              client.println("<a href=\"/?I\">Door Right</a>");
              client.println("<a href=\"/?J\">Kitchen</a>");
              client.println("<a href=\"/?K\">Workroom</a>");
              client.println("</p>");
              client.println("</BODY>");
              client.println("</html>");
    
              delay(2);
              client.stop();
    
              if (readString.indexOf("/?0") > 0) {          //garage open (pin)
                digitalWrite(gu, HIGH);
                delay(50);
                digitalWrite(gu, LOW);
              }
    
              if (readString.indexOf("/?1") > 0) {          //garage stop (pin)
                digitalWrite(gs, HIGH);
                delay(50);
                digitalWrite(gs, LOW);
              }
    
              if (readString.indexOf("/?2") > 0) {          //garage down (pin)
                digitalWrite(gd, HIGH);
                delay(50);
                digitalWrite(gd, LOW);
              }
    
              if (readString.indexOf("/?3") > 0) {          //master bed blind left open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xce);
              }
    
              if (readString.indexOf("/?4") > 0) {          //master bed blind left stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xdf);
              }
    
              if (readString.indexOf("/?5") > 0) {          //master bed blind left down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xfd);
              }
    
              if (readString.indexOf("/?6") > 0) {          //master bed blind right open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xfe);
              }
    
              if (readString.indexOf("/?7") > 0) {          //master bed blind right stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xef);
              }
    
              if (readString.indexOf("/?8") > 0) {          //master bed blind right down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xcd);
              }
    
              if (readString.indexOf("/?9") > 0) {          //master bed blind over open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xee);
              }
    
              if (readString.indexOf("/?a") > 0) {          //master bed blind over stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xff);
              }
    
              if (readString.indexOf("/?b") > 0) {          //master bed blind over down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xdd);
              }
    
              if (readString.indexOf("/?c") > 0) {          //media room blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x9e);
              }
    
              if (readString.indexOf("/?d") > 0) {          //media room blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x8f);
              }
    
              if (readString.indexOf("/?e") > 0) {          //media room blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xad);
              }
    
              if (readString.indexOf("/?f") > 0) {          //gym blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x8e);
              }
    
              if (readString.indexOf("/?g") > 0) {          //gym blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x9f);
              }
    
              if (readString.indexOf("/?h") > 0) {          //gym blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0xbd);
              }
    
              if (readString.indexOf("/?i") > 0) {          //bed 2 blind open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xbe);
              }
    
              if (readString.indexOf("/?j") > 0) {          //bed 2 blind stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xaf);
              }
    
              if (readString.indexOf("/?k") > 0) {          //bed 2 blind down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x8d);
              }
    
              if (readString.indexOf("/?l") > 0) {          //door blind left open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0xae);
              }
    
              if (readString.indexOf("/?m") > 0) {          //door blind left stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0xbf);
              }
    
              if (readString.indexOf("/?n") > 0) {          //door blind left down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x9d);
              }
    
              if (readString.indexOf("/?o") > 0) {          //door blind mid open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x5e);
              }
    
              if (readString.indexOf("/?p") > 0) {          //door blind mid stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x4f);
              }
    
              if (readString.indexOf("/?q") > 0) {          //door blind mid down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x6d);
              }
              
              if (readString.indexOf("/?r") > 0) {          //door blind right open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x4e);
              }
    
              if (readString.indexOf("/?s") > 0) {          //door blind right stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x5f);
              }
    
              if (readString.indexOf("/?t") > 0) {          //door blind right down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x7d);
              }
    
              if (readString.indexOf("/?u") > 0) {          //kitchen open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x7e);
              }
    
              if (readString.indexOf("/?v") > 0) {          //kitchen stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x6f);
              }
    
              if (readString.indexOf("/?w") > 0) {          //kitchen down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x4d);
              }
    
              if (readString.indexOf("/?x") > 0) {          //workroom open (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xdd);
                Serial1.write(0x6e);
              }
    
              if (readString.indexOf("/?y") > 0) {          //workroom stop (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xcc);
                Serial1.write(0x7f);
              }
    
              if (readString.indexOf("/?z") > 0) {          //workroom down (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xee);
                Serial1.write(0x5d);
              }
    
              if (readString.indexOf("/?A") > 0) {          //master bed left pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x10);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xb9);
              }
    
              if (readString.indexOf("/?B") > 0) {          //master bed right pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x20);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x89);
              }
    
              if (readString.indexOf("/?C") > 0) {          //master bed over pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x30);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x99);
              }
    
              if (readString.indexOf("/?D") > 0) {          //media room pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x40);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xe9);
              }
    
              if (readString.indexOf("/?E") > 0) {          //gym pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x50);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xf9);
              }
    
              if (readString.indexOf("/?F") > 0) {          //bed 2 pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x60);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xc9);
              }
    
              if (readString.indexOf("/?G") > 0) {          //door left pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x70);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0xd9);
              }
    
              if (readString.indexOf("/?H") > 0) {          //door mid pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x80);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x29);
              }
    
              if (readString.indexOf("/?I") > 0) {          //door right pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0x90);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x39);
              }
    
              if (readString.indexOf("/?J") > 0) {          //kitchen pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xa0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x09);
              }
    
              if (readString.indexOf("/?K") > 0) {          //workroom pair (485)
                Serial1.write(0x9a);
                Serial1.write(0x09);
                Serial1.write(0xb0);
                Serial1.write(0x00);
                Serial1.write(0x0a);
                Serial1.write(0xaa);
                Serial1.write(0x19);
              }
    
              if (readString.indexOf("/?L") > 0) {    // reley 595 1 on
                relayByte1 = relayByte1 | 0b00000001;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?M") > 0) {    // reley 595 1 off
                relayByte1 = relayByte1 & 0b11111110;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?N") > 0) {    // reley 595 2 on
                relayByte1 = relayByte1 | 0b00000010;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?O") > 0) {    // reley 595 2 off
                relayByte1 = relayByte1 & 0b11111101;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?P") > 0) {    // reley 595 3 on
                relayByte1 = relayByte1 | 0b00000100;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?Q") > 0) {    // reley 595 3 off
                relayByte1 = relayByte1 & 0b11111011;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?R") > 0) {    // reley 595 4 on
                relayByte1 = relayByte1 | 0b00001000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?S") > 0) {    // reley 595 4 off
                relayByte1 = relayByte1 & 0b11110111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?T") > 0) {    // reley 595 5 on
                relayByte1 = relayByte1 | 0b00010000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?U") > 0) {    // reley 595 5 off
                relayByte1 = relayByte1 & 0b11101111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?V") > 0) {    // reley 595 6 on
                relayByte1 = relayByte1 | 0b00100000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?W") > 0) {    // reley 595 6 off
                relayByte1 = relayByte1 & 0b11011111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?X") > 0) {    // reley 595 7 on
                relayByte1 = relayByte1 | 0b01000000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?Y") > 0) {    // reley 595 7 off
                relayByte1 = relayByte1 & 0b10111111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?Z") > 0) {    // reley 595 8 on
                relayByte1 = relayByte1 | 0b10000000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?aa") > 0) {    // reley 595 8 off
                relayByte1 = relayByte1 & 0b01111111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?bb") > 0) {    // reley 595 9 on
                relayByte2 = relayByte2 | 0b00000001;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?cc") > 0) {    // reley 595 9 off
                relayByte2 = relayByte2 & 0b11111110;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?dd") > 0) {    // reley 595 10 on
                relayByte2 = relayByte2 | 0b00000010;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?ee") > 0) {    // reley 595 10 off
                relayByte2 = relayByte2 & 0b11111101;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?ff") > 0) {    // reley 595 11 on
                relayByte2 = relayByte2 | 0b00000100;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?gg") > 0) {    // reley 595 11 off
                relayByte2 = relayByte2 & 0b11111011;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?hh") > 0) {    // reley 595 12 on
                relayByte2 = relayByte2 | 0b00001000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?ii") > 0) {    // reley 595 12 off
                relayByte2 = relayByte2 & 0b11110111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?jj") > 0) {    // reley 595 13 on
                relayByte2 = relayByte2 | 0b00010000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?kk") > 0) {    // reley 595 13 off
                relayByte2 = relayByte2 & 0b11101111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?ll") > 0) {    // reley 595 14 on
                relayByte2 = relayByte2 | 0b00100000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?mm") > 0) {    // reley 595 14 off
                relayByte2 = relayByte2 & 0b11011111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?nn") > 0) {    // reley 595 15 on
                relayByte2 = relayByte2 | 0b01000000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?oo") > 0) {    // reley 595 15 off
                relayByte2 = relayByte2 & 0b10111111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?pp") > 0) {    // reley 595 16 on
                relayByte2 = relayByte2 | 0b10000000;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
    
              if (readString.indexOf("/?qq") > 0) {    // reley 595 16 off
                relayByte2 = relayByte2 & 0b01111111;
                digitalWrite(latchPin, LOW);
                shiftOut(dataPin, clockPin, relayByte2);
                shiftOut(dataPin, clockPin, relayByte1);
                digitalWrite(latchPin, HIGH);
              }
              readString = "";
            }
          }
        }
      }
    }
    
    void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
      int i = 0;
      int pinState;
      pinMode(myClockPin, OUTPUT);
      pinMode(myDataPin, OUTPUT);
      digitalWrite(myDataPin, LOW);
      digitalWrite(myClockPin, LOW);
    
      for (i = 7; i >= 0; i--) {
        digitalWrite(myClockPin, LOW);
        if (myDataOut & (1 << i)) {
          pinState = 1;
        }
        else {
          pinState = 0;
        }
        digitalWrite(myDataPin, pinState);
        digitalWrite(myClockPin, HIGH);
        digitalWrite(myDataPin, LOW);
      }
      digitalWrite(myClockPin, LOW);
    }
    now for me to tackle the next part of the code DMX!!

  5. #5
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,356
    Glad to hear you got it sorted. Out of curiosity, are you using tabs in the editor? May help make your code easier to work with parking those long config strings off elsewhere and keep more of the code in progress on screen.

    Also your row if statements is where you'd often use a switch/case https://www.arduino.cc/en/Reference/SwitchCase . Though in your case sequential Ifs mean it'll correctly handle more than one message at a time.

    Would also be possible to create a function or two to remove all those duplicate shift out commands. Question of course doing that makes your code harder to read so that's very much a taste decision.

  6. #6
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    82
    no im not using tabs at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •