Using 2 different input pins for same trigger

Hi - I am putting together an Iron Man helmet (from a design on Thingiverse).

The default code takes input from a switch to activate the servos to move the face plate up and down. I have a proximity sensor switch wired in on another pin. I can change the code so that the proximity sensor works, but only instead of the regular switch. How can I set both inputs to work?
In the code below the proximity sensor (TACTILE_KEY_PIN) is working. I just need the action_pin to work at the same time. Thanks.

#include "ServoEasing.hpp"
ServoEasing servoTop;
ServoEasing servoBottom;
const int action_pin = 2;
const int ledPin = 6;
const int potPin = A0;
const int TACTILE_KEY_PIN = 4;
int location = 31;
int bottom_closed = 107;
int top_closed = 167;
int bottom_open = 20;
int top_open = 20;
int value;
int maxBrightness;
void setup()
{
pinMode(TACTILE_KEY_PIN, INPUT_PULLUP);
pinMode(action_pin, INPUT_PULLUP);
pinMode(potPin, INPUT);
servoTop.attach(9);
servoBottom.attach(10);
setSpeedForAllServos(190);
servoTop.setEasingType(EASE_CUBIC_IN_OUT);
servoBottom.setEasingType(EASE_CUBIC_IN_OUT);
synchronizeAllServosStartAndWaitForAllServosToStop();
}
void loop()
{
value = analogRead(potPin);
maxBrightness = map(value, 250, 750, 0, 255);
if(digitalRead(TACTILE_KEY_PIN) == LOW)
while(digitalRead(TACTILE_KEY_PIN) == LOW);
{
if (location > bottom_open) {
servoTop.setEaseTo(top_open);
servoBottom.setEaseTo(bottom_open);
synchronizeAllServosStartAndWaitForAllServosToStop();
location = bottom_open;
delay(10);
analogWrite(ledPin, 0);

} else {
servoTop.setEaseTo(top_closed);
servoBottom.setEaseTo(bottom_closed);
synchronizeAllServosStartAndWaitForAllServosToStop();
location = bottom_closed;
delay(50);
analogWrite(ledPin, maxBrightness / 3);
delay(100);
analogWrite(ledPin, maxBrightness / 5);
delay(100);
analogWrite(ledPin, maxBrightness / 2);
delay(100);
analogWrite(ledPin, maxBrightness / 3);
delay(100);
analogWrite(ledPin, maxBrightness);
delay(100);
}
}
}

Thanks in advance! :slight_smile:

Use or (||) if either switch will initiate action or and (&&) if it takes both switches at the same time to initiate action.

if(digitalRead(switch1) == LOW || digitalRead(switch2) == LOW))
{
     // do something if one switch closed
}
if(digitalRead(switch1) == LOW && digitalRead(switch2) == LOW))
{
     // do something if both switches are closed simultaneously 
}
1 Like

Welcome to the forum

You need to investigate the use of the or statement

if ((test1 == true) or (test2 == true))
{
  //execute the code here
}
1 Like

Hello mcbenchy

Try a forum search:

grafik

Hi paulpaulson - not sure if I missed something, but couldn't see anyone else asking the question I am. Most people get stuck with the ServoEasing.hpp issue.

This seems to work, but needs an or and an and. Thanks for your help.

if((digitalRead(action_pin) == HIGH) or (digitalRead(TACTILE_KEY_PIN) == LOW));
while((digitalRead(action_pin) == HIGH) and (digitalRead(TACTILE_KEY_PIN) == LOW));

How are you coming along with the solution that was already posted?

if((digitalRead(action_pin) == HIGH) or (digitalRead(TACTILE_KEY_PIN) == LOW));

does absolutely nothing because the if statement ends with a semicolon. That terminates the statement.

1 Like

@anon57585045 just posted an update :slight_smile:

Please do not update previous posts, it makes replies look weird.

I commented that line out and it works just as well without it :joy:

I didn't actually edit it, I just meant I had added to the thread, think we were posting at the same time.

Okay, but not much point in telling me about a post that I can just see...

Any remaining problems? Can you mark the thread solved by clicking on the solution?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.