Announcement

Collapse
No announcement yet.

4Dbutton not working as expected in "both" mode (using uLCD-32PTU)

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

  • 4Dbutton not working as expected in "both" mode (using uLCD-32PTU)

    Hello,

    I am confused as to how the 4D button works in "both" mode. I have searched through all the 4D systems pdf files and googled it but I am coming up blank. I can see it function correctly in the GTX tool but that does not seem to be how it works in the arduino code. Maybe I am missing something.

    I have 4DButton7 setup as "both" and "Report Message" and what I am expecting is that my code shown below would turn "on" the built in Arduino LED while the button was pressed and turn it "off" when released. However, what I am seeing is that it turns on and stays on. It is as if it is not capturing the "00" when the button is released.

    I have also attached a screen shot of the display settings. Any ideas?

    void myGenieEventHandler(void) // Interface with screen
    {
    genieFrame Event;
    genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below

    if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
    {

    if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)
    {

    if (Event.reportObject.index == 7)
    {
    storeButton1 = genie.GetEventData(&Event);
    while(storeButton1 == 1) {digitalWrite(LED_BUILTIN, HIGH);}
    digitalWrite(LED_BUILTIN, LOW);

    }
    }
    }
    }


    Click image for larger version  Name:	button7.JPG Views:	1 Size:	87.1 KB ID:	62275



    Thanks for any help,
    -Erik
    Last edited by Erik; 4th March 2018, 08:25 PM.

  • #2
    Hello Erik,

    The buttons in ViSi-genie has four settings for the Button Touch Behaviour.

    Yes - Momentary is enabled, touching once will just return a report
    No - It will turn into a latching button with 4 states. Up, Touch pressed (Transition state- going up/down), Down; it will report its up (00) or down (01) position after latching
    On - Same with No, but the button is initially in the down/On position
    Both - Acts mostly as a momentary button, will report both the initial press (01) and release (00) of the button

    I hope this helps,

    Comment


    • #3
      Thank you Jerson, but that is not actually what I am asking. I am aware of the states I am just having an issue with the "both" function.

      The problem is that while I am in the button event function I am unable to exit a while loop that is started with the 01 (button press). That is when the button is released I cannot use it to exit the while loop. I think it is not capturing the 00 event since it is stuck in the while loop.

      What I am doing is using the button in "both" mode so that when the button is pressed longer than 1.5 sec it stores a value but when pressed less than 1.5 sec it uses the contents previously stored. The while loop, that is started with event = 01, is recording the time pressed down. I then try to break the while loop with the release of the button event = 00

      Thanks,
      -Erik

      Comment


      • #4
        Hello Erik,

        I see your issue now. Using a while loop is blocking the Genie event handler, thus not reacting fast enough to capture this release. You might want to try some non-blocking timing options like using system time millis().

        Best regards.

        Comment


        • #5
          Thanks for the help Jerson! I am using millis() but I am using the while loop to know when to subtract millis() from the stored time, not sure how to do it without a while. Here are two sections of code that I tried but neither works, finalTime is what I am after.

          if (Event.reportObject.index == 7)
          {
          storeButton1 = genie.GetEventData(&Event);
          if (storeButton1 == 1)
          {
          keyTime = millis();
          while (storeButton1 == 1);
          {
          if (storeButton1 == 0)
          {
          finalTime = millis()-keyTime;
          break;
          }
          }
          }
          }

          and

          if (Event.reportObject.index == 7)
          {
          int stopWhile = 1;
          storeButton1 = genie.GetEventData(&Event);
          keyTime = millis();
          while (storeButton1 == 1);
          {
          if (stopWhile = 0)
          {
          finalTime = millis()-keyTime;
          break;
          }
          }
          if (storeButton1 == 0)
          {
          stopWhile = 0;
          }

          }
          Last edited by Erik; 6th March 2018, 12:18 PM.

          Comment


          • #6
            I think I figured it out, so simple it is frustrating. When the button is pushed it sets the base time, then when it is released it just measures the time that passed. Keep thinking it needed a while loop.

            if (Event.reportObject.index == 7)
            {
            storeButton1 = genie.GetEventData(&Event);
            finalTime = 0;
            if (storeButton1 == 1)
            {
            keyTime = millis();
            }
            if (storeButton1 == 0)
            {
            finalTime = millis()-keyTime;
            if (KEYDOWN < finalTime)
            {
            location1 = counts;
            }
            gotoLocation(location1);
            }

            }
            Last edited by Erik; 6th March 2018, 04:28 PM.

            Comment

            Working...
            X