alright so here is my issue. I am basically writing an on/off sequence for a haunted prop… to make it simple i have two pneumatic valves that operate open or thru when contact is HIGH and closed when contact is LOW
in my code i am trying to figure out how to make 2 digital OUTPUT pins go HIGH at the same time but go LOW on different delays. CODE to follow.
const int red = 2;
const int blue = 3;
const int black = 4;
const int runLights = 5;
const int strobe = 6;
const int start = 7;
const int twitch = 8;
const int dropBod = 9;
const int surgicalTube = 10;
const int soundR2 = 11;
const int trigger1 = 14;
const int trigger2 = 15;
const int trigger3 = 16;
const int trigger4 = 17;
void setup ()
{
pinMode (red, OUTPUT);
pinMode (blue, OUTPUT);
pinMode (black, OUTPUT);
pinMode (runLights, OUTPUT);
pinMode (strobe, OUTPUT);
pinMode (start, OUTPUT);
pinMode (twitch, OUTPUT);
pinMode (dropBod, OUTPUT);
pinMode (soundR2, OUTPUT);
pinMode (surgicalTube, OUTPUT);
pinMode (trigger1, INPUT);
pinMode (trigger2, INPUT);
pinMode (trigger3, INPUT);
pinMode (trigger4, INPUT);
digitalWrite (runLights, HIGH);
}
void loop ()
{ // identifing different trigger sequences based on button pushed
// running trigger one through for entire first room, trigger two through four TBD
if (digitalRead(trigger1) == HIGH) //first room trigger via NO/NC switch
{
firstRm();
}
if (digitalRead (trigger2) == HIGH)
{
room2();
}
}
void firstRm ()
{ //first room runs lights called out to be red, blue, running lights, strobe lights, and black lights, as well as trigger for chainsaw standalone sequence
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
digitalWrite (runLights, LOW);
delay (2);
digitalWrite (runLights, HIGH);
delay (2);
sawMachine ();
}
void sawMachine ()//stand alone chain saw machine run program
{
digitalWrite (start, HIGH);
delay (100);
digitalWrite (start, LOW);
lightStart ();
}
void lightStart ()//light sequence in first room run program
{
digitalWrite (blue, HIGH);
delay (2);
digitalWrite (blue, LOW);
delay (2);
digitalWrite (red, HIGH);
delay (2);
digitalWrite (red, LOW);
delay (2);
digitalWrite (blue, HIGH);
delay (2);
digitalWrite (blue, LOW);
delay (2);
digitalWrite (red, HIGH);
delay (2);
digitalWrite (red, LOW);
delay (2);
digitalWrite (black, HIGH);
delay (2);
digitalWrite (strobe, HIGH);
delay (2);
digitalWrite (black, LOW);
delay (2);
digitalWrite (strobe, LOW);
delay (2);
twitchingBody();
room2();
}
void room2 ()
{
digitalWrite (soundR2, HIGH);
delay (500);
digitalWrite (soundR2, LOW);
digitalWrite (surgicalTube, HIGH);
delay (2);
digitalWrite (surgicalTube, LOW);
delay (2);
digitalWrite (surgicalTube, HIGH);
delay (2);
digitalWrite (surgicalTube, LOW);
delay (2);
digitalWrite (surgicalTube, HIGH);
delay (2);
digitalWrite (surgicalTube, LOW);
delay (2);
digitalWrite (surgicalTube, HIGH);
delay (2);
digitalWrite (surgicalTube, LOW);
delay (2);
}
void twitchingBody ()
{
digitalWrite (twitch, HIGH);
delay (2);
digitalWrite (twitch, LOW);
delay (2);
digitalWrite (twitch, HIGH);
delay (2);
digitalWrite (twitch, LOW);
delay (2) ;
digitalWrite (twitch, HIGH);
delay (2);
digitalWrite (twitch, LOW);
delay (2);
digitalWrite (twitch, HIGH);
delay (2);
digitalWrite (twitch, LOW);
delay (2);
}
where digitalWrite (twitch,HIGH); is I would like to run that HIGH at the same time digitalWrite (surgicalTube,HIGH); but be able to control their delays seperatly!..
Also I know there is an easier way to compile this just not sure how! any forward links to answers or personal answers would be MUCH appriciated!