Announcement

Collapse
No announcement yet.

Struggling to make a winbutton a toggle button in arduino

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

  • Struggling to make a winbutton a toggle button in arduino

    Hey peopleI want to use a winbutton to control a toggle function in my arduino programm.I assume the reply from the winbutton is an int giving 1 for pressed and 0 for depressed, but I am not sure, cant find data on that.this is my code:
    HTML Code:
    #include 
    
    void setup() {
    
      genieSetup(9600);
      delay (1500); //let the display start up
      genieAttachEventHandler(myGenieEventHandler);
    
      pinMode      (13, OUTPUT) ;
      digitalWrite (13, 0) ;
      genieWriteStr(0,  GENIE_VERSION);
    
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly: 
    
     genieDoEvents();
    
    }
    
    void myGenieEventHandler() 
    {
      genieFrame Event;
      int zone1;            //the button on the screen is named zone1
      int zonestat = 1;     //holds the status of the output
      int previous = 0;     //holds the previous status of the output
      
      char charbuf[50];     //to convert into char for showing state of winbutton in string0
      genieDequeueEvent(&Event);
                            //Read from Button2 for both a Reported Message from Display
      if (genieEventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_WINBUTTON, 2) || genieEventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_WINBUTTON, 2)) 
      {
        zone1 = genieGetEventData(&Event);  //Receive the event data from the zone1
       sprintf(charbuf, "%d", zone1);       //convert zone1 int value to char value to show in string0
       genieWriteStr(0, charbuf);           //write char to string0
      
      
      if (zone1 == 1 && previous == 0)      
        if (zonestat == 1)
          zonestat = 0;
        else
          zonestat = 1;
          
      } 
      
      digitalWrite(13, zonestat);           //write to output 13 and userled0
      genieWriteObject(GENIE_OBJ_USER_LED, 0x00, zonestat);
      
      previous = zone1;
      sprintf(charbuf, "%d", zone1);
      genieWriteStr(0, charbuf);
    
      }
    This works to switch on, but not to switch of, cant find my error...

  • #2


    Hello,

    I presume that you are using a momentary winbutton (which is the default type in ViSi-Genie) to toggle the state of a user LED. Also, I assume that the winbutton was configured to report a message when its status has changed (onChanged).

    To be exact, a winbutton reports a message every time its status has changed from 'pressed' to 'released'. It will report with the data bytes "00 00", which reflect its most current status ('released'). To appreciate this better, you are encouraged to read
    4D-AN-P4017_ViSi-Genie_Connecting_a_4D_Display_to_an_Arduino_Host. Page 21 will show you how to use the GTX tool to analyse the messages coming from the display module. You may use the GTX tool for your project. While experimenting with the GTX tool, you may also refer to the ViSi Genie Reference manual (page 18 for winbuttons). By doing these, you will be able to observe the data from a winbutton.

    app notes are located here: http://www.4dsystems.com.au/appnotes/

    The ViSi Genie Reference manual is located here (bottom part of the page):
    http://www.4dsystems.com.au/product/10/120/Development/4D_Workshop_4_IDE/


    Attached now is a zip file containing a modified version of your sketch. Also included is a Genie program created for the sketch. Attached files momentary_toggles_userLED.zip (2.8 KB)
    Doff

    Comment


    • #3


      An alternative way for you to implement your project is to use toggle buttons. You will need to configure the winbutton to change its type from momentary to toggle. To learn how to do this, please read 4D-AN-P4004-ViSi-Genie-Advanced-Buttons (page 17).

      Attached is a zip file containing a Genie program and an Arduino sketch for this approach. You might notice that the sketch is more straightforward and easier to understand. Also, comments have been added to this sketch and to that posted above. However, there are unnecessary lines that were not pointed out and/or explained well due to lack of space. After reading 4D-AN-P4017_ViSi-Genie_Connecting_a_4D_Display_to_an_Arduino_Host, however, you will be able to figure these out.

      Hope this helps. Attached files toggle_toggles_userLED.zip (2.7 KB)
      Doff

      Comment


      • #4


        Thank you for your reply's guys!

        The explanation was clear! Will be using this a lot in this project.
        I went for the toggle implementation; it shows less buttons on the screen, making it more
        intuitive.

        Greetz Tommie

        Comment

        Working...
        X