Announcement

Collapse
No announcement yet.

Help needed for Arduino sketch - WINBUTTON - for solar light switch

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed for Arduino sketch - WINBUTTON - for solar light switch

    Hi to all from all from a cold South Africa.

    As a first time user of 4D systems and Arduino, I am finding it difficult to write a sketch for my relay automation system that I need for my solar system.

    The screens will be used as replacements for the standard contact switches to give me more control over all switches from a central point.

    I have adapted a sketch from another project that compiles and uploads perfectly, but can not get it to switch over the relays.

    I am using 8 x winbuttons to control the relays and a 24ptu screen.

    Please find code attached.
    Like I said, this is my first time with these systems and your help will be appreciated.

    Attached Files

  • #2
    Hi Wouterd

    Got your WS4 application - but cant really help you without the other half of the puzzle - the Arduino code.
    Please attach that also.

    EDIT: Ignore - its in there. Sorry. Let me have a look.

    Regards
    James

    Comment


    • #3
      you are missing

      genie.DoEvents() from your loop()

      2 other minor things, shown in comments.
      See attachment

      That should work for you now

      Regards
      Attached Files
      James

      Comment


      • vin7102
        vin7102 commented
        Editing a comment
        Hey James,

        Yep I can see it but the.ino link does nothing on my machine.. I can open the initial 8_relay... link just fine, just not the one above. Thanks

      • James_4DSystems
        James_4DSystems commented
        Editing a comment
        Very strange.
        Downloaded fine for me. I'll attach it again below. Maybe try a different browser, or clear your cache or something? Not sure...

      • ESPsupport
        ESPsupport commented
        Editing a comment
        I think if you weren't logged on and tried for it you will get 'a blank screen'. After you log on you will still get a blank screen until you refresh your browser (F5)

    • #4
      Thanks James,
      sorry for the late reply, all working perfectly.

      Comment


      • #5
        vin7102

        Here is the file again. Also in a code box.

        Code:
        #include <genieArduino.h>
        
        Genie genie;
        #define RESETLINE 4
        
        void setup()
        {
          Serial.begin( 9600 );
          genie.Begin(Serial);
        
          genie.AttachEventHandler(myGenieEventHandler);
        
          pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
          digitalWrite(RESETLINE, 1);  // Reset the Display via D4
          delay(100);
          digitalWrite(RESETLINE, 0);  // unReset the Display via D4
        
          delay (3500); //let the display start up after the reset (This is important)
          
          //genie.WriteStr(0, GENIE_VERSION); // NO STRING OBJECT IN YOUR CODE - CANT WRITE TO THINGS WHICH DONT EXIST
        }
        
        void loop()
        {
          genie.DoEvents();  // THIS WAS MISSING - EVENTS NOT PROCESSED WITHOUT IT
        }
        
        void myGenieEventHandler(void)
        
        {
          genieFrame Event;
          genie.DequeueEvent(&Event);
        
          //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
          if (Event.reportObject.cmd == GENIE_REPORT_EVENT) // THIS WAS MISSING - IMPORTANT FILTER INCASE YOU HAVE READ OBJECTS LATER ON
          {
            // If the Event is from a 4D Button object
            if (Event.reportObject.object == GENIE_OBJ_WINBUTTON)
        
              /****************** Relay 1 - Eave Lights   ******************/
            {
              if (Event.reportObject.index == 0x00) // If 4DButton0
              {
                if (genie.GetEventData(&Event) == 1) // if 4DButton0 has been Toggled On
                {
                  digitalWrite(7, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0) // if 4Dbutton0 has been Toggled Off
                {
                  digitalWrite(7, LOW); // Flip the associtated Relay
                }
              }
            }
            /****************** Relay 2 - Back Door Lights   ******************/
        
            {
              if (Event.reportObject.index == 0x01)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(8, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(8, LOW); // Flip the associtated Relay
                }
              }
            }
            /****************** Relay 3 - Pergola Lights   ******************/
        
            {
              if (Event.reportObject.index == 0x04)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(9, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(9, LOW); // Flip the associtated Relay
                }
              }
            }
            /****************** Relay 4 - Garden Lights   ******************/
        
            {
              if (Event.reportObject.index == 0x05)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(10, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(10, LOW); // Flip the associtated Relay
                }
              }
            }
            /****************** Relay 5 - Pool Lights   ******************/
        
            {
              if (Event.reportObject.index == 0x03)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(11, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(11, LOW); // Flip the associtated Relay
                }
              }
            }
        
            /****************** Relay 6 - Pool Pump   ******************/
        
            {
              if (Event.reportObject.index == 0x02)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(12, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(12, LOW); // Flip the associtated Relay
                }
        
              }
            }
            /****************** Relay 7 - Pool Heater   ******************/
        
            {
              if (Event.reportObject.index == 0x07)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(6, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(6, LOW); // Flip the associtated Relay
                }
              }
            }
            /****************** Relay 8 - Pool Fountain   ******************/
        
            {
              if (Event.reportObject.index == 0x08)
              {
                if (genie.GetEventData(&Event) == 1)
                {
                  digitalWrite(3, HIGH); // Flip the associtated Relay
                }
                else if (genie.GetEventData(&Event) == 0)
                {
                  digitalWrite(3, LOW); // Flip the associtated Relay
                }
              }
            }
          }
        }
        Regards
        Attached Files
        James

        Comment


        • vin7102
          vin7102 commented
          Editing a comment
          Thanks James, This link works just fine! Much Appreciated!
      Working...
      X