Bit of a noob but I've had good luck, until now. I'm working on a setup where you have 8 switches and once they are in the proper position, one led goes off, one led comes on and a relay is triggered. Thought I was on the right track but I'm not having any luck. My guess is that it at the point where the switch conditions are. Any help would be greatly appreciated
/*
Pin 2 is switch 1
Pin 3 is switch 2
Pin 4 is switch 3
Pin 5 is switch 4
Pin 6 is switch 5
Pin 7 is switch 6
Pin 8 is switch 7
Pin 9 is switch 8
Pin 10 is red Led
Pin 11 is grn Led
Pin 12 is relay Com
Pin 13 is n/a
Pin 2,3,4,5,6,7,8,9 Input
*/
const bool led = 13;
// set pin numbers:
const int interruptPin0 = 2; // the number of the pushbutton pin 0
const int interruptPin1 = 3; // the number of the pushbutton pin 1
const int interruptPin2 = 4; // the number of the pushbutton pin 2
const int interruptPin3 = 5; // the number of the pushbutton pin 3
const int interruptPin4 = 6; // the number of the pushbutton pin 5
const int interruptPin5 = 7; // the number of the pushbutton pin 6
const int interruptPin6 = 8; // the number of the pushbutton pin 7
const int interruptPin7 = 9; // the number of the pushbutton pin 8
const int redLedPin = 10; // the number of the RED LED pin
const int grnLedPin = 11; // the number of the GRN LED pin
const int relayPin = 12; // the number of the relay pin
// variables will change:
int buttonState0 = HIGH; // variable for reading the pushbutton0 status
int buttonState1 = HIGH; // variable for reading the pushbutton1 status
int buttonState2 = HIGH; // variable for reading the pushbutton2 status
int buttonState3 = HIGH; // variable for reading the pushbutton3 status
int buttonState4 = HIGH; // variable for reading the pushbutton5 status
int buttonState5 = HIGH; // variable for reading the pushbutton6 status
int buttonState6 = HIGH; // variable for reading the pushbutton7 status
int buttonState7 = HIGH; // variable for reading the pushbutton8 status
int puzzle = LOW; // variable for state puzzle
// the setup funtion runs once when you press reset or power the board
void setup() {
//initialize digital pin 10, 11, 12 as outputs
pinMode(redLedPin, OUTPUT);
pinMode(grnLedPin, OUTPUT);
pinMode(relayPin, OUTPUT);
// initialize digital pin 2,3,4,5,6,7,8,9 as inputs with internal pullup resistors
pinMode(interruptPin0, INPUT_PULLUP);
pinMode(interruptPin1, INPUT_PULLUP);
pinMode(interruptPin2, INPUT_PULLUP);
pinMode(interruptPin3, INPUT_PULLUP);
pinMode(interruptPin4, INPUT_PULLUP);
pinMode(interruptPin5, INPUT_PULLUP);
pinMode(interruptPin6, INPUT_PULLUP);
pinMode(interruptPin7, INPUT_PULLUP);
// set the outputs
digitalWrite(redLedPin, HIGH); // turn the red LED on
digitalWrite(grnLedPin, LOW); // turn the green LED off
digitalWrite(relayPin, LOW); // relay off
}
// the loop funtion runs over and over again forever
void loop() {
// read the state of the puzzle
puzzle = (digitalRead(buttonState0 == HIGH) && (buttonState1 == LOW) && (buttonState2 == LOW) && (buttonState3 == LOW) && (buttonState4 == LOW) && (buttonState5 == LOW) && (buttonState6 == LOW) && (buttonState7 == LOW));
// check if the puzzle is solved
// if it is, the puzzle state is low or zero volts
if (puzzle == LOW) {
// delay to avoid randomly flicking switches
delay (1500);
if (puzzle == LOW) {
// turn red led off, grn led on and trigger relay
digitalWrite(redLedPin, LOW); // turn the red LED off
digitalWrite(grnLedPin, HIGH); // turn the green LED on
digitalWrite(relayPin, HIGH); // relay on
// wait time for reset
delay (10000);
}
}
else { // else reset the puzzle
// turn redLed on and relay off
digitalWrite(redLedPin, HIGH); // turn the red LED on
digitalWrite(grnLedPin, LOW); // turn the green LED off
digitalWrite(relayPin, LOW); // relay off
}
}