Ghost Trap Arduino Code

Hi Guys,

i need help i have a ghost trap i prited out and need help with the code.

i will have one button on the pedal to activate the different sections of code.
i have the wave shield and the sound board but if you have any recomendations.

so iwhat i want to happen is

power switch turned on
red led1 to turn on

pedal pushed
doors open with 2 servos

pedal pushed
sound file to activate with 3 leds flashing and smoke

pedal pushed
sound stops with doors closing

10 segemtn bar graph fills with a red led flashing with a beeping noise.

pedal push
reset to the top?

i have the arduino mega and standard.
i consider myself new at this but an old hand at electronics!

please can you help.

Many thanks
Mark

frenchy3736249:
please can you help.

It's not easy to do that when you have not posted your program.

...R

This forum is for helping others with existing code. If you want code written for you, head on over to "Gigs and Collaborations" and bring your wallet.

here is the code i have so far.

i will be editing the times on the leds and servos to correspond with teh sound clip that is playing.i havent added the smoke motor as yet on this code

as it stands the sounds doesnt stop it just keeps looping is there anyway to stop this.

#include <Servo.h>

Servo servoLeft; // Define left door servo
Servo servoRight; // Define right door servo

int Rledpin = 2; // define red led pin
int Yledpin = 11; //define yellow led
int motorPin = 29; //defineing smoke motor pin

int sound = 24; // define sound pin

int MainLed1 = 7; // set main flashing leds
int MainLed2 = 6;
int MainLed3 = 5;

int bar1LED = 31; // define bar graph leds
int bar2LED = 33;
int bar3LED = 35;
int bar4LED = 37;
int bar5LED = 39;
int bar6LED = 41;
int bar7LED = 43;
int bar8LED = 45;
int bar9LED = 47;
int bar10LED = 49;

void setup() {
servoLeft.attach(9); // Set left servo to digital pin 10
servoRight.attach(10); // Set right servo to digital pin 9

pinMode (Rledpin, OUTPUT); //set Red LED
pinMode (Yledpin, OUTPUT); //set yellow led

pinMode (sound, OUTPUT); ///set sound

pinMode (MainLed1, OUTPUT); //set main flahsing leds
pinMode (MainLed2, OUTPUT);
pinMode (MainLed3, OUTPUT);

pinMode (bar1LED, OUTPUT);
pinMode (bar2LED, OUTPUT);
pinMode (bar3LED, OUTPUT);
pinMode (bar4LED, OUTPUT);
pinMode (bar5LED, OUTPUT);
pinMode (bar6LED, OUTPUT);
pinMode (bar7LED, OUTPUT);
pinMode (bar8LED, OUTPUT);
pinMode (bar9LED, OUTPUT);
pinMode (bar10LED, OUTPUT);

pinMode (motorPin, OUTPUT);

}

void loop() { // Loop through motion tests

digitalWrite (sound, LOW);
delay (20);

servoLeft.write(30); //door left open
servoRight.write(150); //door right open

delay(1);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 1st
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 2nd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

digitalWrite (MainLed1, HIGH); // flahsing middle leds 3rd
delay(100);
digitalWrite (MainLed1, LOW);
delay(100);

digitalWrite (MainLed2, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed2, LOW);
delay(100);

digitalWrite (MainLed3, HIGH); // flahsing middle leds
delay(100);
digitalWrite (MainLed3, LOW);
delay(100);

servoLeft.write(150);
delay(50);
servoRight.write(30);

delay(1000);

digitalWrite (bar1LED, HIGH);
delay (100);
digitalWrite (bar2LED, HIGH);
delay (100);
digitalWrite (bar3LED, HIGH);
delay (100);
digitalWrite (bar4LED, HIGH);
delay (100);
digitalWrite (bar5LED, HIGH);
delay (100);
digitalWrite (bar6LED, HIGH);
delay (100);
digitalWrite (bar7LED, HIGH);
delay (100);
digitalWrite (bar8LED, HIGH);
delay (100);
digitalWrite (bar9LED, HIGH);
delay (100);
digitalWrite (bar10LED, HIGH);
delay (100);

digitalWrite (Yledpin, HIGH);
delay(1000);

digitalWrite (Rledpin, HIGH);
delay(500);
digitalWrite (Rledpin, LOW);
delay(500);
digitalWrite (Rledpin, HIGH);
delay(500);
digitalWrite (Rledpin, LOW);
delay(500);
digitalWrite (Rledpin, HIGH);
delay(500);
digitalWrite (Rledpin, LOW);
delay(500);
digitalWrite (Rledpin, HIGH);
delay(500);
digitalWrite (Rledpin, LOW);
delay(500);
digitalWrite (Rledpin, HIGH);
delay(500);
digitalWrite (Rledpin, LOW);
delay(500);

digitalWrite (Yledpin, LOW);

digitalWrite (bar1LED, LOW); ////bar grapoh off
delay (50);
digitalWrite (bar2LED, LOW);
delay (50);
digitalWrite (bar3LED, LOW);
delay (50);
digitalWrite (bar4LED, LOW);
delay (50);
digitalWrite (bar5LED, LOW);
delay (50);
digitalWrite (bar6LED, LOW);
delay (50);
digitalWrite (bar7LED, LOW);
delay (50);
digitalWrite (bar8LED, LOW);
delay (50);
digitalWrite (bar9LED, LOW);
delay (50);
digitalWrite (bar10LED, LOW);

delay (20000);

}

beautiful, you need to read a tutorial on “functions”, it will make your code a lot easier to read and use and may reduce your code to about 50 lines instead of how many you have now

frenchy,
Read the 'how to use this forum' thread.
Edit your post and put the code inside of code tags.
It keeps the torches and pitchforks to a minimum.

You really need to learn about arrays. As soon as you start putting 1 and 2 and more on the end of variables, you would probably be better served by arrays.

And +1 on the use of functions to avoid duplicating code.

Hi thank your for you posts guys
i have turned a corner on this now

i tried adding a button to activate the code but no such luck it turns on Ok but doesn't stop with button press or not.

please can you help

  if(digitalRead(buttonPin) == LOW) //funcitons based off of button pulling input pin LOW
  {
     if(run == 0)
     {
         run = 255;
     }
     else
     {
         run = 0;
     }
  }

  if(run > 0)
  {
   // then the code goes here.

frenchy3736249:
but doesn’t stop with button press or not.

That’s because of all the delay()s that you have. If you want a responsive program don’t use delay() anywhere. Have a look at how millis() is used to manage timing without blocking in Several things at a time

Also have a look at how functions are used in Planning and Implementing a Program

And, as someone else said, learn about arrays.

Please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.

…R

Can't see your code.