Hi, first time poster and new to Arduino.
I'm intending to use the Uno R3 to run 7 servos operating points on a model railway.
I found a Sketch (attached - hopefully) elsewhere on this site that allowed a single push-button SPST (momentary) operation of a servo in either direction.
I'm set-up with the SPST attached to Pin 2 & the Servo attached to pin 3 which runs perfectly.
I'd like to run all 7 switches off of Pin 2 using a resistor circuit and attach the servos to pins 3-9.
How do I include the instructions for the other 6 servos in the Sketch so they operate as simultaneously as possible?
#include <VarSpeedServo.h>
const byte switchPinA = 2;
VarSpeedServo servo;
const byte servoPin = 3;
byte switchAstate = HIGH;
byte servoPos = 90;
byte posA = 50;
byte posB = 130;
void setup() {
pinMode(switchPinA, INPUT_PULLUP);
servo.attach(3);
}
void loop () {
readButtons();
moveServo();
}
void readButtons() {
switchAstate = digitalRead(switchPinA);
}
void moveServo() {
if (switchAstate == LOW) {
if (servoPos == posA) {
servoPos = posB;
}
else
{
servoPos = posA;
}
switchAstate = HIGH;
}
servo.write(servoPos, 10, true);
delay(1);
}
One_Button_Servo_Control.ino (596 Bytes)