I am trying to assign more than one joystick button to a single relay_rev. I have tried using an “=” sign, I have tried adding a new line but the program recognizes one but not the other. How can I do it? Thanks!
The default code includes some code that controls some of the relays, make sure you check if that is overriding some of your stuff.
Use C’s | “or” operator.
relay3_rev = p1_sw_trig | p2_sw_trig;
Here is the code I have:
relay5_rev = p3_sw_aux1;
relay5_rev = p4_sw_aux1;
There are no other references to the relay in the “Buttons to Relays” section. It seems to me that it should work???
Ah, I misunderstood what you are trying to do (thought you meant multiple relays to one button, not vice versa). Alan Anderson has it right. Use the “or” operator just as he suggested.
relay5_rev = p3_sw_aux1;
relay5_rev = p4_sw_aux1;
The first assignment sets the value based on the switch on port 3. The second assignment then sets the value based on the switch on port 4, regardless of what the first assignment did. p3_sw_aux1 is completely irrelevant to the final result.
You need to set the value based on a combination of the two switches. The | “or” operator will return a value of zero if both its operands are zero, and a value of one if either or both are one.
relay5_rev = p3_sw_aux1 | p4_sw_aux1;
Thanks Alabn. I tried that and it still does not work.
Use some printf’s or other diagnostic and determine if the trigger that isn’t working is actually changing the variable.
You’ll have to give more details than that if you want useful help. What are you expecting to happen? How are you testing to see if it happens? What happens instead of what you expect?
Specifically, what do you have connected to the Spike, and what else is it connected to?
It works! You guys are awesome! Thanks so much!