Home AMX User Forum AMX Design Tools

How to create toggle button?

winstonmawinstonma Junior MemberPosts: 45
I think it's a simple problem but I have no idea how to figure that out.

There is a toggle button which I dun know how to turn it on when I pushed the button. Thanks for the help.

Comments

  • DarksideDarkside Member Posts: 345
    Are you trying to toggle the feedback on a button on a touch panel?
    Or are you trying to control a device with a toggle control such as VCR power?

    If you can be more specific, I'm sure it can be solved quite simply!
  • winstonmawinstonma Junior Member Posts: 45
    Actually I want both, either it will toggle when I push it. Or I can toggle from the AMX Master. Thanks
  • Spire_JeffSpire_Jeff Formerly Caffeinated Programmer Posts: 1,917
    BUTTON_EVENT[dvTP,nBTN]
    {
      PUSH:
      {
        IF([BUTTON.INPUT.DEVICE,BUTTON.INPUT.CHANNEL])
        {
          OFF[BUTTON.INPUT.DEVICE,BUTTON.INPUT.CHANNEL]
          // SEND OFF COMMAND HERE.... or whatever code you need
        }
        ELSE
        {
          ON[BUTTON.INPUT.DEVICE,BUTTON.INPUT.CHANNEL]
          // SEND ON COMMAND HERE.... or whatever code you need
        }
      }
    }
    
    
    This is one way to accomplish what you want. Make sure the button Feedback option is set to channel.

    Jeff
  • yuriyuri Junior Member Posts: 861
    Jeff,

    that's a long way to do something very simple :p
    BUTTON_EVENT[dvTP, 1]
    {
    PUSH:
    {
    [dvTP,1] = ![dvTP, 1]
    }
    }
    
  • Chip MoodyChip Moody Junior Member Posts: 727
    Then there are those of us that were taught a long time ago to not use touch panel channels to store/track states. :)
    BUTTON_EVENT [TP,1]
    {
      PUSH:
      {
        Flagvar = !Flagvar  
      }
    }
    
    // Or to free up memory and not waste the space to track a boolean value,
    // you can also use a free channel on a relay, serial,
    // or other physical device port - just not one from a touchpanel!
    
    BUTTON_EVENT [TP,2]
    {
      PUSH:
      {
        [SomeDev,250] = ![SomeDev,250]
      }
    }
    
    
    TIMELINE_EVENT [FeedbackTimeline]
    {
      [TP,1] = Flagvar
      [TP,2] = [SomeDev,250]
    }
    


    - Chip
  • yuriyuri Junior Member Posts: 861
    how fast is that timeline running chip? realtime? ;)
  • HARMAN_icraigieHARMAN_icraigie Technical Trainer II, Harman Professional University Posts: 593
    Chip Moody wrote:
    Then there are those of us that were taught a long time ago to not use touch panel channels to store/track states. :)
    BUTTON_EVENT [TP,1]
    {
      PUSH:
      {
        Flagvar = !Flagvar  
      }
    }
    
    // Or to free up memory and not waste the space to track a boolean value,
    // you can also use a free channel on a relay, serial,
    // or other physical device port - just not one from a touchpanel!
    
    BUTTON_EVENT [TP,2]
    {
      PUSH:
      {
        [SomeDev,250] = ![SomeDev,250]
      }
    }
    
    
    TIMELINE_EVENT [FeedbackTimeline]
    {
      [TP,1] = Flagvar
      [TP,2] = [SomeDev,250]
    }
    


    - Chip




    So just what exactly is the difference between a wired touchpanel and some other wired device?
  • yuriyuri Junior Member Posts: 861
    a wired touchpanel can always be 'unwired' hence losing your feedback :)
  • winstonmawinstonma Junior Member Posts: 45
    o thanks

    I tried but the the button have no effect at all. Do I need set some kinds of properties for the pushbutton?
  • DarksideDarkside Member Posts: 345
    winstonma wrote:
    o thanks

    I tried but the the button have no effect at all. Do I need set some kinds of properties for the pushbutton?

    Make sure the feedback attribute on your touch panel button is set to CHANNEL.
  • Chip MoodyChip Moody Junior Member Posts: 727
    Uh - that was an excercise left to the reader. :)

    For those that do feedback in timelines and find their button just doesn't toggle states quickly enough for them, there's no reason you couldn't do this:
    BUTTON_EVENT [TP,2]
    {
      PUSH:
      {
        [SomeDev,250] = ![SomeDev,250]
        [TP,2] = [SomeDev,250]
      }
    }
    
    
    TIMELINE_EVENT [FeedbackTimeline]
    {
      [TP,2] = [SomeDev,250]
    }
    

    That gets you the immediate state change, and also allows for any potential changes from elsewhere in the code to be reflected by the traditional feedback statement.
    yuri wrote:
    how fast is that timeline running chip? realtime? ;)
  • Chip MoodyChip Moody Junior Member Posts: 727
    I don't remember the explaination - or if I was even given one at the time - but many years ago I had some buttons coded to track their own states. When the system started behaving oddly, AMX T.S. said "oh - yeah - you shouldn't do that". I went to tracking states with variables, and the odd behavior went away. I seem to recall hearing at some point in time that the way the three channels work in touch panels is slightly different than other devices. Might have had something to do with the timing involved as well - I.E., changing a channel state almost immediately after getting a channel event from it.

    All I know is that I've seen it cause "wonkiness" in the past - in my own code and others - and the wonkiness ceased as soon as variables or a non-tp device's channels were used.

    - Chip

    icraigie wrote:
    So just what exactly is the difference between a wired touchpanel and some other wired device?
  • JeffJeff Junior Member Posts: 374
    Thats interesting, because in current versions of the AMX Programmer class, they teach you to use TP Channels to track things, as well as "channels" on 232 devices and other such imaginary channels.

    I wonder if it was older TPs or something that were screwy (wonky?) like that, and they've fixed it now.

    J
  • Chip MoodyChip Moody Junior Member Posts: 727
    Perhaps - maybe Netlinx/G4 panels don't have the same issues.

    Keep in mind - I have 10 years of (self?) brainwashing in place, so I'm sticking with the Old Skool method. :)

    - Chip
  • winstonmawinstonma Junior Member Posts: 45
    By the way... are there any 'By Default' toggle button? So I dun need to send the toggle status back to the panel?
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    There is a difference between feedback channels and output channels; the differences are subtle and not well documented. That is why they used to not recommend using button channels for tracking, because they are feedback channels. It could very well be they realized how confusing this is and make them work identically. As I recall, the primary issue was when you used them in MUTUALLY_EXCLUSIVE.

    As for timeline feedback, I have come to the conclusion that for channel feedback on a real device (not virtuals), you can drop it right in mainline (DEFINE_PROGRAM) with no ill effects. The feedback only goes to the panel when the channel changes. SEND_COMMANDs for text feedback, on the other hand, will go out in a steady stream if you do that, so it's a bad idea and probably a bad habit. What I do, is create a CALL or a function for panel updates. Then I'll just run that in my timeline, or dump it right in DEFINE_PROGRAM if its very simple and I'm being lazy. The other advantage is you can use the GoTo Sub function in studio to easily find your feedback routines (they really, really ought to make a similar tool to find specific events).
Sign In or Register to comment.