Announcement

Collapse
No announcement yet.

Problems with buttons

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

  • Problems with buttons

    Hi all,

    I'm trying to get my touch buttons to work as the first step to my redesigned project. The problem is that only my first button will go down when pressed. I can't figure out why only ONE button would respond to touch. Any idea would be great.

    [HTML]
    #platform "uOLED-32024-P1T"
    #constant TRUE 1
    #constant FALSE 0
    #constant BUTTONCOLOR 0x000CB1
    var touchx;
    var touchy;
    //------------------------
    func drawbuttons()
    display_Vsync();
    //all buttons are drawn RAISED
    gfx_Button(UP, 35,0, BUTTONCOLOR, 0x00, 2, 2, 2, "Speak Time");
    gfx_Button(UP, 45,70, BUTTONCOLOR, 0x00, 2, 2, 2, "Set Time");
    gfx_Button(UP, 45,140, BUTTONCOLOR, 0x00, 2, 2, 2, "Set Hour");
    gfx_Button(UP, 35,210, BUTTONCOLOR, 0x00, 2, 2, 2, "Set Minute");
    gfx_Button(UP, 15,280, BUTTONCOLOR, 0x00, 2, 2, 2, "Re/set Alarm");
    endfunc
    //------------------------

    //-----------------------
    func buttonpressed(var touchx, var touchy)
    display_Vsync();
    //if speak time button is touched set button to DOWN
    if(touchx>35&&touchx0&&touchy45&&touchx70&&touchy45&&touchx140&&touchy

  • #2


    Mika,

    Tips...

    Check your button regions in buttonpressed(), they're not quite right.

    In the absence of a debugger, putting in a few print statements / pauses will allow you to check whether variable are what you expect them to be.

    With touch regions, drawing some test rectangles is helpful.

    This should hopefully get you moving again.

    Steve

    Comment


    • #3


      I found my button regions by printing touchx and touchy for each button and finding the outer limits for each, so I'm not sure how they could be off. Assuming they are off though, I believe this should give me a decent amount of tolerance considering the size of the buttons.

      I'm still not understanding why only the first button would function when I've simply duplicated the code for that button and changed my region. Do I need to declare a new touch region for each button or can I just declare the entire screen and use the (x,y) as I've done?

      Comment


      • #4


        I've not run the code, so it's difficult to say what is happening with just first button activating. (FYI, it's better to not post code in a code block, as characters get translated.)

        Once you've issued a touch_Set(0) then the whole screen is active for touch. You don't need to issue a touch_DetectRegion() at all unless you want to limit it to a smaller region.

        Ignoring completely changing you're writing your program... I'd be inclined to set up an array with the touch locations and use that to drive the button display *and* touch region detection.

        Steve

        Comment


        • #5


          Mika,

          See the gfx_get(2); and gfx_Get(3); commands. Used together, they return the bottom-right coordinates of the last drawn object that uses only top-left coordinates (button, Image, etc.).

          See the attached 4DGL code snippet (as text) for an example of using arrays to keep track of all four (x1,y1,x2,y2) coordinates of your buttons. Makes the touch boundry test much more exact.

          Also, you might want to take a look at the touchchecker() function logic. Using the negative logic that you're using might not give you the results you're looking for.

          You might try something like the following:

          HTML Code:
              var state; 
          state := touch_Get(TOUCH_STATUS);                 // touch activity?
          if(state != NOTOUCH)
          if(state == TOUCH_PRESS)
          touchx:=touch_Get(1);
          touchy:=touch_Get(2);
          buttonpressed(touchx,touchy);
          endif
          
          if(state == TOUCH_RELEASE)
          touchx:=touch_Get(1);
          touchy:=touch_Get(2);
          drawbuttons();
          endif
          endif
          It a bit easier to follow and provides a fast exit if no touch.



          Unless you set a touch region, the system defaults to the full screen. You might want to set a touch reqion that encloses your buttons so that touches other than on the buttons will be ignored.

          (The other) Steve

          Attached files _Buttons_test.txt (2.7 KB)
          Any technology, sufficiently developed, is indistinguishable from magic. A.C. Clark(RIP)

          NEW! Lower prices on all 4D Systems products for 2009 and continuing into 2010!
          http://shop.littlepcbsolutions.com

          Comment


          • #6


            wow thanks for the help! Now my buttons are working.

            to ignore touches outside of my button regions I would just declare a touch detect region for each of the buttons correct?

            Thanks again for the help I would be lost and angry without it haha!

            Comment


            • #7


              Sorry, I may have mislead you with my comment about defining a touch area to ignore touches other than on the buttons. Only one touch area can be defined (it's not possible to define a separate area for each button). I made that comment before running and testing your code and realizing that your buttons covered nearly the whole screen.

              Using the ImageControl and the image commands on the PICASO displays using 4DGL allows you to use images, of buttons or anything else you want, and then use the img_Touched() command to get the index of the image that was touched. This gives you the advantage of using high resolution images as controls and simplifies the coding to figure out which control was touched.

              And I'm glad that you're happy and excited rather than lost and angry.

              Steve
              Any technology, sufficiently developed, is indistinguishable from magic. A.C. Clark(RIP)

              NEW! Lower prices on all 4D Systems products for 2009 and continuing into 2010!
              http://shop.littlepcbsolutions.com

              Comment


              • #8


                Ok, now that that issue is solved, I'm looking at the pinout for J1 and J2 the 32024-P1T and I see that there are several available IO pins (Pins 17, 19, 21, 23, 25, 27 on J1) is there a way for me to manipulate the voltage levels here? In the 4DGL manual it shows an example for 320XX-PMD3X [pin_Set(mode,pin)], but only a few available pins.

                Are the functions the same for the 32024-P1T so that I may use these to trigger my MCU.

                Comment


                • #9


                  Mika,

                  We will be updating the docs soon to indicate the available I/O functions on the new P1(T) modules.
                  Atilla

                  Comment


                  • #10


                    ok great I look forward to seeing some more great work from 4D!

                    Comment

                    Working...
                    X