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! ![]()
