Announcement

Collapse
No announcement yet.

Issues with WINBUTTON function within my Arduino Uno code.

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

  • Issues with WINBUTTON function within my Arduino Uno code.

    Hi,
    I have attached my Arduino code "Sprinkler System R5.ino.
    I cannot attach my Visie Genie project "Sprinkler System R2.4DGenie" project as this post will not allow the upload of such a file?

    In particular I am referring to Form 2 of the Visie Genie project. This form is especially setup for testing my Arduino code. The Arduino code refers to all of the objects in Form 2.

    I have these defined variable as noted below within the code.

    int Behind_Lawn_Selected; //Water Behind Lawn button is pressed
    int Behind_Garage_Selected; //Water Behind Garage button is pressed
    int Retaining_Wall_Selected; //Water Retaining Wall button is pressed
    int Front_Lounge_Selected; //Water Front Lounge button is pressed
    int Front_Garage_Selected; //Water Front Garage button is pressed
    int Pump_Only_Selected; //Start Pump Only button is pressed

    In the Arduino code I set these variables depending on which WINBUTTON is selected from the LCD screen, Form 3, an example is below.

    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {
    if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) // If the Reported Message was from a WINBUTTON
    {
    if (Event.reportObject.index == 20) // If WINBUTTON with index 20 is selected
    {
    Behind_Lawn_Selected = 1;
    genie.WriteObject(GENIE_OBJ_LED, 6, 1); // Write Slider0 value to LED Digits 0
    genie.WriteObject(GENIE_OBJ_LED, 7, 0);
    genie.WriteObject(GENIE_OBJ_LED, 8, 0);
    genie.WriteObject(GENIE_OBJ_LED, 9, 0);
    genie.WriteObject(GENIE_OBJ_LED, 10, 0);
    genie.WriteObject(GENIE_OBJ_LED, 11, 0);
    //genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, 1);

    }
    }
    }

    You will notice further down in the code I perform a task if Behind_Lawn_Selected == 1; the code is below.

    if(Behind_Lawn_Selected == 1)
    {
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, 1);
    //delay(1000);
    }


    Basically this last bit of code highlighted in purple just does not work and I don't know why. Can anyone please assist me.

    If I write this code in purple within the loop of the if (Event.reportObject.index == 20), the code works, but this is not what I need for my programe.
    I need to remember within my code that WINBUTTON 20 has been pressed by setting "Behind_Lawn_Selected = 1;" and then using that variable throughout my code to perform other
    functions.

    Hope my explanation makes sense.
    Attached Files

  • #2
    Hi Rob,

    I cannot attach my Visie Genie project "Sprinkler System R2.4DGenie" project as this post will not allow the upload of such a file?
    You can upload the zip file of your project. On your Workshop4 application, go to File and select "Zip Project".

    Basically this last bit of code highlighted in purple just does not work and I don't know why. If I write this code in purple within the loop of the if (Event.reportObject.index == 20), the code works,
    There should be no reason for that to happen as it is included in the same method. The variable used was also declared on the same method and not on the if-condition itself. You should see the same result. Does the widgets you are writing on Event.reportObject.index == 20 exists? I cannot think of anything that can cause that behavior.

    As a side note, on your local function (void myGenieEventHandler(void)), you should always explicitly declared the values of your variables.
    Code:
    int Behind_Lawn_Selected = 0; //Water Behind Lawn button is pressed
    int Behind_Garage_Selected = 0; //Water Behind Garage button is pressed
    int Retaining_Wall_Selected = 0; //Water Retaining Wall button is pressed
    int Front_Lounge_Selected = 0; //Water Front Lounge button is pressed
    int Front_Garage_Selected = 0; //Water Front Garage button is pressed
    int Pump_Only_Selected = 0; //Start Pump Only button is pressed
    I need to remember within my code that WINBUTTON 20 has been pressed by setting "Behind_Lawn_Selected = 1;" and then using that variable throughout my code to perform other
    Are you only planning to use the variable on the same method? Or are you planning to use the variable on different methods throughout your code? If it is the latter, you could use a global variable.

    I hope this helps.

    Best Regards,
    Kevin

    Comment


    • #3
      Hi Kevin,

      Thanks for taking the time to look through this issue. I have been working on this for a long time and it has me stumped as well.

      I have attached two more Arduino files that I tested this morning. Once is named "Sprinkler_System_R5_This_Code_Works" and the other is named "Sprinkler_System_R5_This_Code_Does_Not_Work"

      The code in both programes are essentially the same but coded slightly differently. Ultimately I need to use the code in the file that does not work, otherwise I have no idea on how to code my project. Surely it cannot be that hard, others must be doing it.

      I have uploaded one video for the code that works and and one video file showing what happens with the Arduino file that does not work. Hope it's clear. Basically the video shows me pressing WINBUTTON20 and you can see the LED and LED DIGITS are all over the place, ON/ OFF, numbers changing randomly etc.

      I have uploaded the visie project as well "Sprinkler System R2.zip"

      My test code in the arduino files refers to objects within Form(2) of the visie genie project. Form (2) is accessible via the "Test Screen" button on the home page.

      Regards
      Rob
      Attached Files

      Comment


      • #4
        Hi,

        Thank you for the attached files, and videos.

        If you would notice on the video (Video Showing Code Not Working.mp4), you will see that the Led widgets are blinking on and off when the Winbutton is pressed and stays on at the last Led (Led11). This is due to the if-condition on your code - which always executes once the value is set to 1. The variables declared are global. By setting the state to 1, the value will not change until you iterate another value again.

        Either you set the state to 0 so you can procure the expected output, or remove your global declaration, and move it on the Event Handler method.

        Let me know if that helps.

        Best Regards,
        Kevin
        Attached Files

        Comment


        • #5
          Hi Kevin,

          Thanks for getting back to me again.
          You hit the nail on the head. When I reset my variables back to 0 and tried the code it worked perfectly.
          The modified code is attached.

          "or remove your global declaration, and move it on the Event Handler method."
          I know what you mean by this but i don't understand how this would also resolve the issue. Is it because each time the Event Handler is called the variables are initially all set to zero?


          Regards
          Rob
          Attached Files

          Comment


          • John Kevin
            John Kevin commented
            Editing a comment
            Hi Rob,

            I am glad that you managed to solve the issue.

            "I know what you mean by this but i don't understand how this would also resolve the issue. Is it because each time the Event Handler is called the variables are initially all set to zero?"

            Basically, yes.

            Best Regards,
            Kevin

        • #6
          Hi Kevin,

          Thanks so much for your time and effort. It was simple error in the end.
          Now I can complete my project, hopefully without any more silly errors.😁

          Again, much appreciated.


          Regards
          Rob

          Comment


          • John Kevin
            John Kevin commented
            Editing a comment
            Hi Rob,

            Sure, no problem. Yes, I do also hope for the completion of your project.
            Should you need further assistance, please don't hesitate to ask.

            Best Regards,
            Kevin
        Working...
        X