Momentary buttons to set one pin value

More
4 years 9 months ago #230827 by AgentWD40
My game controller pendant has 4 momentary buttons x, y, a, and b. I would like to assign a value to each of these buttons and each time a button is pressed I’d like to set a pin’s value to the pressed button’s assigned value. I’d like this pins value to persist after the momentary buttons are released and until the next button press overwrites it. Ideas?

This seems like it should be very straight forward but I’m still learning hal and am not seeing any components that fit the bill in the docs. I’m tempted to just write one but really don’t want to if I don’t have to.

Please Log in to join the conversation.

More
4 years 9 months ago #230837 by rodw

Please Log in to join the conversation.

More
4 years 9 months ago #230861 by AgentWD40
I saw that one but I'm not sure how it would be implemented. Can you show me how one might configure so that toggling one button on would toggle three others off? At the same time toggling one off should not toggle the others on.

Please Log in to join the conversation.

More
4 years 9 months ago #230875 by AgentWD40
I whipped up a python component that accomplishes what I'm after.

My first question is can I accomplish the same thing with standard components?

My second question is for something like this what is an appropriate sleep time?
Code:
#!/usr/bin/env python3 import hal, time h = hal.component("select4") h.newpin("in0", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("in1", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("in2", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("in3", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("sel0", hal.HAL_BIT, hal.HAL_IN) h.newpin("sel1", hal.HAL_BIT, hal.HAL_IN) h.newpin("sel2", hal.HAL_BIT, hal.HAL_IN) h.newpin("sel3", hal.HAL_BIT, hal.HAL_IN) h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT) h.ready() last_selection = 'in0' try: while 1: time.sleep(0.005) if h['sel0']: last_selection = 'in0' elif h['sel1']: last_selection = 'in1' elif h['sel2']: last_selection = 'in2' elif h['sel3']: last_selection = 'in3' h['out'] = h[last_selection] except KeyboardInterrupt: raise SystemExit

Please Log in to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum