Announcement

Collapse
No announcement yet.

Polling a WinButton???

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

  • Polling a WinButton???

    Hey Everybody,

    I have a form as shown in the attachment. I want to remain on this form as long as I am trying to manually navigate and I would like to continuously update the GPS coordinates (every 1-2 seconds) UNTIL the BACK button is pressed.

    I have a getInput() function in the main loop of my code. But when I get to this form, I am no longer in that loop. So created another loop within the manualNavigation() function to getInput() and look at the 3rd byte which is the INDEX. In my case the BACK button INDEX byte is 0x0E. Even while polling while(rx_byte[2] != 0x0E), I cannot seem to exit the while loop even if I press the BACK button.

    Is there any type of interrupt that I can use with a button press?


    void manualNavigate(void)
    {
    thrusterMasterPower(1); // turn on thruster master power
    delay(100); // wait for thruster to respond
    while(rx_byte[2] != 0x0E)
    {
    getCurrentGPS();
    updateCurrentGPSLatCoords(0x02, 0x00);
    updateCurrentGPSLonCoords(0x02, 0x07);
    delay(25);
    getInput();
    delay(25);
    }
    }



    TIA,
    --Neal
    Attached Files
    TIA,

    Neal

  • #2
    Hi Neal,

    "Even while polling while(rx_byte[2] != 0x0E), I cannot seem to exit the while loop even if I press the BACK button."
    To exit a while loop, you could use break statement inside a conditional statement. For more information regarding break
    statement, please refer to this link:
    https://www.arduino.cc/reference/en/...ructure/break/

    For example:
    Code:
    while (rx_byte[2] != 0x0E) {
        //do something here
        if (getInput() == n) {
            break;
        }
    }
    I hope this helps.

    Good luck and kind regards,
    Sherwin

    Comment


    • #3
      Dear Sherwin,

      Thank you for your reply.

      If I make a function call to getInput(), I am not sure whether or not the MEGA 2560 will wait for input. In other words, what if there is no input? I do have a couple of short 25ms delays in my code because the code runs so fast I was afraid that the button touch might not get sensed. Not really a button debounce check, and I am not quite sure if my delay really does anything.

      Because I analyze the results of getInput() is several ways (looking at different bytes for WinButton, slider, dipswitch, keypad, etc.), I have to look for input and then look at the various bytes using if/then and switch statements.

      I will take another look at my code and try to implement your logic. I will report back with the results.

      Thank you.
      --Neal
      TIA,

      Neal

      Comment


      • #4
        Hi Neal,
        I do have a couple of short 25ms delays in my code because the code runs so fast I was afraid that the button touch might not get sensed.
        It would be best to use millis function instead of delay. Instruction on how you could do that can be found here.

        As you may already know, delay would essentially freeze your program, and thus your host controller cannot respond to any external events coming from the display module.

        I hope this helps.

        Good luck and kind regards,
        Sherwin

        Comment

        Working...
        X