I want to create a useless box that has 5 toggle switches and a corresponding arm for each switch. I also want to create a master on/off switch for the entire circuit so that I can control when it is active or not. I've attached my switch to the vin and also the positive side of my 9v power supply. The other side of the power supply is attached to the negative side of the battery.
The way I attempted to do this was by checking the status of the switch at the top of my loop, but I'm struggling to declare the switch since it's only attached to the vin pin of my arduino. What is a better way to do this? I'm new to using arduinos and can't seem to find any solutions online, so I apologize if this is a dumb question
#include <Servo.h>
Servo doorServo;
Servo fingerServo1;
Servo fingerServo2;
Servo fingerServo3;
Servo fingerServo4;
Servo fingerServo5;
int onOff = 5;
int swPin1 = 0;
int swPin2 = 1;
int swPin3 = 2;
int swPin4 = 3;
int swPin5 = 4;
int pos = 0;
int selectedMove = 0;
int selectedMove2 = 0;
int selectedMove3 = 0;
int selectedMove4 = 0;
int selectedMove5 = 0;
void setup() {
pinMode(swPin1, INPUT_PULLUP);
pinMode(swPin2, INPUT_PULLUP);
pinMode(swPin3, INPUT_PULLUP);
pinMode(swPin4, INPUT_PULLUP);
pinMode(swPin5, INPUT_PULLUP);
doorServo.attach(8);
doorServo.write(0);
fingerServo1.attach(9);
fingerServo1.write(80);
fingerServo2.attach(10);
fingerServo2.write(80);
fingerServo3.attach(11);
fingerServo3.write(80);
fingerServo4.attach(12);
fingerServo4.write(80);
fingerServo5.attach(13);
fingerServo5.write(80);
}
void loop() {
if (digitalRead(onOff) == LOW){
if (digitalRead(swPin1) == LOW) { //switch pin 1
if (selectedMove > 2) {
selectedMove = 0;
}
if (selectedMove == 0) {
for (pos = 0; pos < 140; pos += 3) {
doorServo.write(pos);
delay(20);
}
for (pos = 0; pos < 200; pos += 4) {
fingerServo1.write(pos);
delay(10);
}
for (pos = 200; pos >= 0; pos -= 4) {
fingerServo1.write(pos);
delay(20);
}
for (pos = 140; pos >= 0; pos -= 3) {
doorServo.write(pos);
delay(10);
}
}else if (selectedMove == 1) { //move 2
}
selectedMove += 1;
}
