Before I begin my story and the situation I am in, I want to start by saying I am completely new to Arduino and coding, I've made mobile apps before in LUA so I have some concept of programming, but nothing like this.
My brother and I are big in to Halloween and we love making props for the yard. We have always run the props off of a bunch of push switches that we would have to control. This year I thought we could try to automate things a little bit. So I did some research and found that an Arduino + a MonsterShield would work awesome...the only problem is Hauntsoft is on hiatus for 2014. So I did some more research and found the Seeeduino Relay Shield, figuring it would be perfect, because all the things I am using are 12v, I just need solenoids to turn on and off at different times. In the very near future I am planning on adding PIR sensors so the relays will trigger when someone walks by. But, for now I am just trying to create a sequence of on and off so I can have a big box jump up and down on the floor like something is trying to get out, then stop for a moment and have the lid spring open to reveal a werewolf monster thing. The lid can not open when the box is jumping or it will break apart. I also looked up how to create a push switch recorder like an actual prop controller, but that is for another day.
here is my code so far:
int RELAY1 = 7;
int RELAY2 = 6;
void setup()
{
// Initialise the Arduino data pins for OUTPUT
pinMode(RELAY1,OUTPUT);
pinMode(RELAY2,OUTPUT);
}
void loop()
{
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(300); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(300);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(300); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(300);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(100); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(100); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(200); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(200); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(700);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(700); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(200); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(200);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(200); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(300); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(300);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(300); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(300);
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
delay(3000); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
delay(100);
}
I wanted the box to jump kind of erratic, so the jumps do not look all the same. (There is probably an easier way to code this, I just don't know how to yet) This works exactly the way I want the box to jump.
Now as soon as I add this code to the end, it does not fire after RELAY 1 is finished, and when it does fire RELAY2 does not turn off
digitalWrite(RELAY2,LOW); // Turns ON Relays 2
delay(300); // Wait 2 seconds
digitalWrite(RELAY2,HIGH);
I am trying to have RELAY2 turn on after RELAY1, but RELAY1 can not turn on until RELAY2 has finished. It seems so simple but since I am so new to this, I can't wrap my head around it. If someone would be kind enough to point me in the right direction that would be awesome! From what I've been reading the delay function is not the way to go. Thanks in advance for any advice!