1 (edited by pinkman3100 2018-08-19 06:43:39)

Topic: Can I use Switch to develop some logic and not control a pin?

I want to process the data (0 for low and 1 for high) from the Switch and develop a logic accordingly in my loop function. Is this possible? I think this will require a bitstream of 1s or 0s according to switch value. Please Help

2

Re: Can I use Switch to develop some logic and not control a pin?

In the configuration of the Switch, just set "Snap to Pin" to "-" {nothing}

In your sketch you can then write something like...

if (RemoteXY.switch_1) {
  your code here
}

There's no need for any == in the comparison statement, because switch = 1 evaluates as "true"

or you can use the Switch-Case construct like

Switch (RemoteXY.switch_1) {
  case 0:
    your code here for switch off
  break;
  case 1:
    your code here for switch on
  break;
}

2B, or not 2B, that is the pencil ...

3

Re: Can I use Switch to develop some logic and not control a pin?

Thanks a lot. That's what I thought.

4

Re: Can I use Switch to develop some logic and not control a pin?

In actual fact, I never use "Snap to pin" at all because if adds the following lines into your code areas...

#define PIN_switch_1 8   // pin number you have "snapped to"

in Setup :  pinMode (PIN_switch_1, OUTPUT);

in loop() :  digitalWrite(PIN_switch_1, (RemoteXY.switch_1==0)?LOW:HIGH);

... which makes it a "permanent" snap. There may be times when you don't want the switch to control the pin, so I prefer to create my own control code.

2B, or not 2B, that is the pencil ...