can someone please scan this for me and tell me where there are problems,
would like some help
Thanks
#include <Time.h>
#include <TimeAlarms.h>
// Some macros for defining time intervals in milliseconds
// #define seconds_in_ms(s) ((s)*1000UL)
// #define minutes_in_ms(m) ((m)*60UL*1000UL)
/* Haunted house
possibly 8 events one at a time or more than 1 played random but one after the other like shuffle them then play them back to back but only the number equeal to inputs
turn on and off a play relay
turn on and off a stop relay
turn on and off a amplifier
then have 4 rooms each with a speaker to be turned on eather in 1 room or 2 rooms or 4 rooms or 4 rooms 1 at a time in shuffle again
then stop and wait for a random time between start of between 3 to 30 minute before doing it again
so if 1 input then event 1 + play + amp
if 2 input then event 1 + play + amp folowed by event 2 + play + amp
if input greater than 2 then play + amp + events shuffled and then played after each other
rooms if choice 1 then room 1
rooms if 2 then 2 rooms
rooms if choice 3 then 4 rooms shuffle then each after each other
hope this makes sense
*/
int SoundOutA = 2; //play sound 1
int SoundOutB = 3; //play sound 2
int SoundOutC = 4; //play sound 3
int SoundOutD = 5; //play sound 4
int SoundOutE = 6; //play sound 5
int SoundOutF = 7; //play sound 6
int SoundOutG = 8; //play sound 7
int SoundOutH = 9; //play sound 8
int SpeakOutA = 10; //speaker 1 relay
int SpeakOutB = 11; //speaker 2 relay
int SpeakOutC = 12; //speaker 3 relay
int SpeakOutD = 13; //speaker 4 relay
int PlayOutA = 22; //Play this may be power on relay
int AmpOnOutA = 24; //Amplfier On relay
int StopOutA = 26; //Stop
int SwitchInputA = 31; //Switch sound 1
int SwitchInputB = 33; //Switch sound 2
int SwitchInputC = 35; //Switch sound 3
int SwitchInputD = 37; //Switch sound 4
int SwitchInputE = 39; //Switch sound 5
int SwitchInputF = 41; //Switch sound 6
int SwitchInputG = 43; //Switch sound 7
int SwitchInputH = 45; //Switch sound 8
int SpeakerConA = 47; //speaker config 1 this configs for 2 rooms
int SpeakerConB = 49; //speaker config 2 this configs for 4 rooms
int SpeakerConC = 51; //speaker config 3 thia configs all speakers in a random sequence 1 after the other
int LightSensA = 53; //Light Senser is it dark so begin
int SpeakVar = 0;
int SoundPlay = 0;
int ran;
int buttonState;
int buttonState1;
int buttonState2;
int time4 = 4500;
long RandOff = 0; // Initialize a variable for the OFF time
long previousMillis = 0;
long interval = 1000;
void randomTimer(){
int period = random(5000,20000); // get a new random period
Alarm.timerOnce(period, randomTimer); // trigger for another random period
}
void setup() // run once, when the sketch starts
{
Serial.begin(9600);
pinMode(SoundOutA, OUTPUT); //sound 1
pinMode(SoundOutB, OUTPUT); //sound 2
pinMode(SoundOutC, OUTPUT); //sound 3
pinMode(SoundOutD, OUTPUT); //sound 4
pinMode(SoundOutE, OUTPUT); //sound 5
pinMode(SoundOutF, OUTPUT); //sound 6
pinMode(SoundOutG, OUTPUT); //sound 7
pinMode(SoundOutH, OUTPUT); //sound 8
pinMode(PlayOutA, OUTPUT); //play
pinMode(AmpOnOutA, OUTPUT); //amp on
pinMode(SpeakOutA, OUTPUT); //speaker 1
pinMode(SpeakOutB, OUTPUT); //speaker 2
pinMode(SpeakOutC, OUTPUT); //speaker 3
pinMode(SpeakOutD, OUTPUT); //speaker 4
pinMode(StopOutA, OUTPUT); //stop
pinMode(SwitchInputA, INPUT); //switch 1
pinMode(SwitchInputB, INPUT); //switch 2
pinMode(SwitchInputC, INPUT); //switch 3
pinMode(SwitchInputD, INPUT); //switch 4
pinMode(SwitchInputE, INPUT); //switch 5
pinMode(SwitchInputF, INPUT); //switch 6
pinMode(SwitchInputG, INPUT); //switch 7
pinMode(SwitchInputH, INPUT); //switch 8
pinMode(SpeakerConA, INPUT); //speaker 1 on
pinMode(SpeakerConB, INPUT); //speaker 2 on
pinMode(SpeakerConC, INPUT); //speaker 3 on
pinMode(LightSensA, INPUT); //Light senser
}
void loop() // run over and over again scan inputs then play them
{
randomSeed (analogRead (0)); // randomize
SoundPlay = random (1,10); // generate random output pin
RandOff = random (2000,30000); // generate OFF time between 2 and 9 seconds in this case 20 to 30 seconds till proved
unsigned long currentMillis = millis();
digitalWrite(SpeakOutA, LOW);
digitalWrite(SpeakOutB, LOW);
digitalWrite(SpeakOutC, LOW);
digitalWrite(SpeakOutD, LOW);
digitalWrite(SoundOutA, LOW); //play sound 1
digitalWrite(SoundOutB, LOW); //play sound 2
digitalWrite(SoundOutC, LOW); //play sound 3
digitalWrite(SoundOutD, LOW); //play sound 4
digitalWrite(SoundOutE, LOW); //play sound 5
digitalWrite(SoundOutF, LOW); //play sound 6
digitalWrite(SoundOutG, LOW); //play sound 7
digitalWrite(SoundOutH, LOW); //play sound 8
if (digitalRead(SpeakerConA) == HIGH && digitalRead(SpeakerConB) == LOW) // choose speakers, this works on its one but not with the random light below
{
digitalWrite(SpeakOutA, HIGH);
Alarm.delay(time4);
}
else
{
digitalWrite(SpeakOutA, LOW);
}
if (digitalRead(SpeakerConA) == LOW && digitalRead(SpeakerConB) == HIGH) // choose speakers, this works on its one but not with the random light below
{
digitalWrite(SpeakOutA, HIGH);
digitalWrite(SpeakOutB, HIGH);
}
else
{
digitalWrite(SpeakOutA, LOW);
digitalWrite(SpeakOutB, LOW);
}
if (digitalRead(SpeakerConA) == HIGH && digitalRead(SpeakerConB) == HIGH)
{
digitalWrite(SpeakOutA, HIGH);
digitalWrite(SpeakOutB, HIGH);
digitalWrite(SpeakOutC, HIGH);
digitalWrite(SpeakOutD, HIGH);
}
else
{
digitalWrite(SpeakOutA, LOW);
digitalWrite(SpeakOutB, LOW);
digitalWrite(SpeakOutC, LOW);
digitalWrite(SpeakOutD, LOW);
}