Problem is if I open the necklaceDoor first, nothing happens. I have to open the ringDoor first. That turns everything on. Then with the necklaceDoor open, the stepper motor will turn off and the lights and music will continue to play. But I want to be able to open the necklaceDoor first and play the music with the lights. I do not want it to matter which one is opened first. I also realized that if I can get an or statement to work within an and statement I could do away with the fourth if statement completely. Both ringDoor open and necklaceDoor open, as well as ringDoor closed and necklaceDoor open have the same outcome. Now if I switch the door states in the third if statement, I get necklaceDoor only plays audio after closed(original problem) but if both doors are open and then ringDoor is closed, the music will shut off after the stepper timer is done and then start again after necklaceDoor is closed?!?!?!?
#include <SD.h>
#include <TMRpcm.h>
#include <Stepper.h>
TMRpcm tmrpcm;
const int stepsPerRevolution = 2048; //Number of pulses per revolution
const int ringDoor=2; //Ring door
const int necklaceDoor=7; //Necklace door
const int relayPower=22; //Turn relay on
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
Serial.begin(9600); //Start connection with computer
if (!SD.begin(53)) //Chip pin on card
{
Serial.println("failed!"); //SD card did not read
return;
}
tmrpcm.speakerPin = 46; //Speaker output pin
myStepper.setSpeed(5); //Stepper speed
pinMode(ringDoor,INPUT); //Check state of ring door magnetic switch, NO
pinMode(necklaceDoor,INPUT); //Check state of necklace door magnetic switch, NO
pinMode(relayPower,OUTPUT); //Relay enable for 12V LED
digitalWrite(ringDoor,HIGH); //Make door closed read high on start up
digitalWrite(necklaceDoor,HIGH); //Make door closed read high on start up
digitalWrite(relayPower,LOW); //Make relay off on start up
}
void loop() {
if ((digitalRead(ringDoor)==HIGH)&&(digitalRead(necklaceDoor)==HIGH))
{ //ring door and necklace door is closed, everything is off
digitalWrite(relayPower,LOW);
}
if ((digitalRead(ringDoor)==LOW)&&(digitalRead(necklaceDoor)==HIGH))
{ //ring door is open and necklace door is closed, lights on, stepper motor spinning, music playing
digitalWrite(relayPower,HIGH);
tmrpcm.play("music.wav");
myStepper.step(stepsPerRevolution);
delay(500);
myStepper.step(-stepsPerRevolution);
delay(500);
}
if ((digitalRead(ringDoor)==LOW)&&(digitalRead(necklaceDoor)==HIGH))
{ //ring door closed and necklace door open, lights on, stepper motor off, music playing
digitalWrite(relayPower,HIGH);
tmrpcm.play("music.wav");
}
if ((digitalRead(ringDoor)==LOW)&&(digitalRead(necklaceDoor)==LOW))
{ //ring door and necklace door open, lights on, stepper motor off, music playing
digitalWrite(relayPower,HIGH);
tmrpcm.play("music.wav");
}
}
Please and thank you to any and all who help. It is greatly appreciated. Yes, I asked the the original question and the answer I received not only did not work, somehow neither latch worked anymore.