How to group inputs for IF statements?
Chad1
Posts: 26
Hey everyone,
Let's say I have ten switches, and any time one of them is high I want to turn on an LED. Instead of writing something like this in SPIN...
repeat
if (ina[SW1] == 1) or (ina[SW2] == 1) or (ina[SW3] == 1) or ... or (ina[SW10] == 1)
***Turn on LED***
...could I write something like this? (Pseudocode for the sake of clarity)
InputGroup = [SW1, SW2, ... , SW10]
repeat
if InputGroup == 1
***Turn on LED***
Thanks in advance for your help!
Let's say I have ten switches, and any time one of them is high I want to turn on an LED. Instead of writing something like this in SPIN...
repeat
if (ina[SW1] == 1) or (ina[SW2] == 1) or (ina[SW3] == 1) or ... or (ina[SW10] == 1)
***Turn on LED***
...could I write something like this? (Pseudocode for the sake of clarity)
InputGroup = [SW1, SW2, ... , SW10]
repeat
if InputGroup == 1
***Turn on LED***
Thanks in advance for your help!
Comments
To make code appear how I did it, retaining indentation and such, put it in [noparse] [/noparse].
EDIT:
Here's a more advanced solution that doesn't need contiguous pins and tells you which pins are on: