Announcement

Collapse
No announcement yet.

While loop

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

  • While loop

    Hi, please help.

    I have a button on a touch screen ("Menu"), and wrote a method that does the following:
    • If the button is pressed and released within 3 seconds the display should send character 's' to the serial port and return.
    • If the button is pressed and held-on for more that 3 seconds the display should send character 'r' and return.
    • If the screen is pressed but not at the button the display should send character 'n' to the serial and return.
    The button is at x=300, y=500, width=200 and height=50.
    Bellow is the code in the method.

    How/ When is the touch state updated and cleared? If the button is pressed, does the state stay the same until the button is released?


    state := touch_Get(TOUCH_STATUS);
    if(state == TOUCH_PRESSED)
    x:= touch_Get(TOUCH_GETX);
    y:= touch_Get(TOUCH_GETY);
    if((x >= 300 && x <= 500) && (y >= 416 && y <=466))
    img_SetWord(hndl, iMenu, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
    img_Show(hndl,iMenu) ;
    delay();
    sys_SetTimer(TIMER0, 3000);
    while(touch_Get(TOUCH_STATUS)== TOUCH_PRESSED)
    if(sys_GetTimer(TIMER0)==0)
    serout('r');
    pause(1);
    return;
    endif
    wend
    serout('s');
    pause(1);
    return;
    endif
    serout('f');
    return;
    endif

  • #2
    Phalits,
    you should be able to use a different type of combination of touch_Get(mode). There are 4-modes to work with
    touch_Get(NOTOUCH)
    touch_Get(TOUCH_PRESSED)
    touch_Get(TOUCH_RELEASED)
    touch_Get(TOUCH_MOVING)
    It seems like you might be able to use these in different loops for your <3 seconds, >3 seconds, and then check x and y, or !=touch_TestArea() for outside the button.

    Keith

    Comment


    • Phalits
      Phalits commented
      Editing a comment
      Thank you, I replaced the while loop statement with [while(touch_Get(TOUCH_STATUS) != TOUCH_RELEASED)] and it works.

  • #3
    Hi Phalits,

    Might want to play around with this one:
    Code:
        touch_Set(TOUCH_ENABLE);                            // enable the touch screen
    
        repeat
    
            state := touch_Get(TOUCH_STATUS);               // get touchscreen status
            n := img_Touched(hndl,-1) ;
    
            //-----------------------------------------------------------------------------------------
            if(state == TOUCH_PRESSED)                        // if there's a press
                x := touch_Get(TOUCH_GETX);
                y := touch_Get(TOUCH_GETY);
    
                if((x >= 300 && x <= 500) && (y >= 416 && y <=466))
                img_SetWord(hndl, iMenu, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
                img_Show(hndl,iMenu) ;
    
                endif
    
            endif
    
            //-----------------------------------------------------------------------------------------
            if(state == TOUCH_RELEASED)                      // if there's a release
    
    
            endif
    
            //-----------------------------------------------------------------------------------------
            if(state == TOUCH_MOVING)                       // if it's moving
                x := touch_Get(TOUCH_GETX);
                y := touch_Get(TOUCH_GETY);
            endif
    
        forever
    You can also try to print some text to test the state changes.

    4D-AN-00054: Designer or ViSi Touch Detection
    http://www.4dsystems.com.au/appnote/4D-AN-00054/

    Hope this helps,

    Comment


    • Phalits
      Phalits commented
      Editing a comment
      Thanks Joseph, I got it right.
Working...
X