Announcement

Collapse
No announcement yet.

Holding a winbutton

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

  • Holding a winbutton

    Dear Sir/Madam,

    I've got a question about the winbutton.
    I can make it go count up and down by just tapping on the button on the screen and the digits will go along with it.
    But i rather have an extra function as by holding the winbutton that it will spam my counter up, as of it will take a long time by just tapping it.
    I've tried to use buttonstates on my Arduino like how it usualy should've worked but then the whole winbutton doesn't count anymore, can you help me with it?


    Thank you in advance!

    Juliyano

  • #2
    Hi,

    To help you better, can you share your project with us?

    You can also try setting the winbutton's momentary property to 'Both'. This way, you can read the button states('1' = Pressed and '0' = Released). You can try the sample project attached and feel free to modify it.

    Best Regards
    Attached Files

    Comment


    • #3
      Hello Ivan,

      The attached files didn't seem to work, if you would like to help me with my program i would really appreciate it.
      I'm currently using an uLCD-50-DCT-CLB, for code see below:


      Code:
      #include<genieArduino.h>
      #define RESETLINE 4
      Genie genie;
      unsigned long currenttime;
      int setv;
      int seta;
      int RED = 44; // Red LED is connected to pin 9
      int GREEN = 45; // Green LED is connected to pin 10
      int BLUE = 46; // Blue LED is connected to pin 11
      
      void setup() {
      // put your setup code here, to run once:
      Serial1.begin(19200);
      genie.Begin(Serial1);
      genie.AttachEventHandler(myGenieEventHandler);
      
      pinMode(RESETLINE, OUTPUT);
      delay(1000);
      
      digitalWrite(RESETLINE, 1);
      delay(100);
      digitalWrite(RESETLINE, 0);
      delay(3500);
      
      genie.WriteContrast(10);
      TCCR5B = TCCR5B & B11111000 | B00000010;
      pinMode(RED, OUTPUT);
      pinMode(GREEN, OUTPUT);
      pinMode(BLUE, OUTPUT);
      }
      void loop() {
      // put your main code here, to run repeatedly:
      genie.DoEvents();
      analogWrite(RED, setv);
      analogWrite(BLUE, seta);
      
      
      }
      void myGenieEventHandler(void){
      
      genieFrame Event;
      genie.DequeueEvent(&Event);
      if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 0))
      {
      setv++;
      //genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, setv);
      if(setv > 255){
      setv = 0;
      }
      }
      if(Event.reportObject.index == 1){
      setv--;
      if(setv < 0){
      setv = 255;
      }
      }
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, setv);
      if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 2))
      {
      seta++;
      //genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, setv);
      if(seta > 255){
      seta = 0;
      }
      }
      if(Event.reportObject.index == 3){
      seta--;
      if(seta < 0){
      seta = 255;
      }
      }
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, seta);
      if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 7))
      {
      setv = 0;
      seta = 0;
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, seta);
      genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, setv);
      }
      if(genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 6))
      {
      genie.WriteObject(GENIE_OBJ_FORM, 0x03, true);
      }
      
      }



      Thank you for your time,

      Juliyano
      Last edited by Juliyano satimoen; 13 October 2021, 09:40 PM.

      Comment


      • #4
        Hi,

        Can you share your ViSi Genie project? It would be helpful to figure out what's wrong.

        To ensure you will share it completely, you can follow this article for the instructions: How can I share my projects?

        Best Regards

        Comment


        • #5
          Hello,

          This is just my test project at this time (see the attachment below), it should work with the code from the previous post.


          Greetings,

          Juliyano
          Attached Files

          Comment


          • #6
            Hi,

            It seems that the code doesn't properly evaluate the data from winbuttons 1 and 3. In your Arduino sketch, you are only checking the index of the object. I have modified your code for the buttons and, it works as expected. You can check the Arduino sketch attached.

            I hope this helps

            Best Regards
            Attached Files

            Comment


            • #7
              Hello Ivan,

              Unfortunately the attached file doesn't seem to work but I do see what the problem was with the digits on te winbuttons 1 and 3. But the problem is that i can't make it work is with the holding part, as for arduino naturally it has to do with an extra buttonstate with an edge detection. But I don't know how to fix this attached to a winbutton. Can you help me with that?


              Greetings,

              Juliyano

              Comment


              • #8
                Hi,

                But the problem is that i can't make it work is with the holding part, as for arduino naturally it has to do with an extra buttonstate with an edge detection.
                You can used two button states. For example:


                Code:
                int buttonState0; //Current button0 state
                int prev_buttonState0; //previous button0 state

                Set the button 1 to 3 to 'BOTH' to receive the values '1' and '0' to detect whether the button is pressed or released. The 'buttonState0' receives the current button state. It will also update the 'prev_buttonState0'. If these states are equal, it means you are holding the button down. Here's the snippet of code you can try.

                To read the button state:

                Code:
                if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 0))
                {
                buttonState0 = genie.GetEventData(&Event); //Read button0
                prev_buttonState0 = buttonState0; //update previous button state
                }

                To show the value in Leddigits:

                Code:
                if (buttonState0 && (buttonState0 == prev_buttonState0) && (currentMillis - previousMillis >= buttonDelay)) {
                previousMillis = currentMillis;
                setv++;
                if (setv > 255) {
                setv = 0;
                }
                genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, setv);
                }
                You can try your Arduino sketch that I modified for your reference and, let me know if this will work.

                Best Regards
                Attached Files

                Comment

                Working...
                X