Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Button Press or Release with ST

2021-12-24
2022-01-03
  • santigonzalez

    santigonzalez - 2021-12-24

    Id like to manage the buttonpress or release event on an object ie. an image using ST and not the visualization. I found that there is a library for this, cmp3clutter, but i couldnt find out how to use it properly and there is no example of usage anywhere.
    If somebody could help me it would be much appreciated.

     
  • santigonzalez

    santigonzalez - 2021-12-28

    I was able to do it and i leave the code for someone who might need it.
    //Declare global variables to associate with the actions you want the objects to do
    buttonenter1 : UDINT;
    buttonleave1 : UDINT;

    //in the LoopCode you have to associate each variable to the event you want to register
    IF pagina<>paginaanterior THEN
    buttonenter1:= PantallaPrincipal.PowerButton.RegisterEvent(ADR(Events.EVENT_ENTER));
    buttonleave1:= PantallaPrincipal.PowerButton.RegisterEvent(ADR(Events.EVENT_LEAVE));
    paginaanterior:=pagina;
    END_IF

    //In MyEvents(FUN) you can say to the program what to do each time an event is triggered.

    CASE pagina OF

    1:
        IF event.ID= buttonenter1 THEN
            plc_prg.power:=TRUE;    
        ELSIF event.ID=buttonleave1 THEN
            plc_prg.power:=FALSE;   
        END_IF
    

    end_case

     
  • m.prestel

    m.prestel - 2022-01-03

    Hey,
    I am unsure what you are trying to do?

    Why is "Execute ST Code" not usable for you?

    Best regards,
    Marcel

     
  • mondinmr

    mondinmr - 2022-01-03

    Is not very clear what do you want?
    But a simple event press and release with debounce could be as follow:

    VAR
      tmDebounce : TON;
      oldState : BOOL;
    END_VAR
    
    ....
    
    tmDebounce(IN := buttonState <> oldState, PT := T#50ms);
    IF tmDebounce.Q THEN
      oldState := buttonState;
      IF buttonState THEN
        eventPressFunction();
      ELSE
        eventReleaseFunction();
      END_IF
    END_IF
    

    Functions, or if you prefer methods or actions are called only once after debounce time on falling or rising edges.

     

Log in to post a comment.