Thanks!
I guess i should have told you guys the bigger picture of what I am doing.
I need two push buttons to control six solenoids
first time you push button1 solenoid1 opens
second time solenoid 2 opens
third time solenoid 3 opens
and same thing for button two
I also need two noise makers to go off a couple seconds before and a couple of seconds after the all the solenoids opens
It would be very nice to be able to use the two push bottons at the same time.
and what i have read so far the delay functions does not allow that
Is there a way to make but a delay in somehow and be able to use both buttons?
I tried to change around a stopwatch code so that when you pushed the button it started counting the seconds and then at second 3 and 5 the noise makers went off and then at second 6 it stoped and reset.
but that failed because i did not know what i was doing.
here is the code i have so far
[code]
const int buttonPin = 2;
const int buttonPin2 = 3;
const int soleniod1Pin = 13;
const int soleniod2Pin = 12;
const int soleniod3Pin = 11;
const int soleniod4Pin = 10;
const int soleniod5Pin = 9;
const int soleniod6Pin = 8;
const int sound1Pin = 7;
const int sound2Pin = 6;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter2 = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(soleniod1Pin, OUTPUT);
pinMode(soleniod2Pin, OUTPUT);
pinMode(soleniod3Pin, OUTPUT);
pinMode(soleniod4Pin, OUTPUT);
pinMode(soleniod5Pin, OUTPUT);
pinMode(soleniod6Pin, OUTPUT);
pinMode(sound1Pin, OUTPUT);
pinMode(sound1Pin, OUTPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
buttonPushCounter++;
Serial.println("on");
Serial.print("button1: ");
Serial.println(buttonPushCounter, DEC);
}
else {
Serial.println("off");
}
}
if (buttonState2 != lastButtonState2) {
if (buttonState2 == HIGH) {
buttonPushCounter2++;
Serial.println("on");
Serial.print("button2 : ");
Serial.println(buttonPushCounter2, DEC);
}
else {
Serial.println("off");
}
}
lastButtonState = buttonState;
lastButtonState2 = buttonState2;
if (buttonPushCounter == 1) {
digitalWrite(soleniod1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod1Pin, LOW);
}
if (buttonPushCounter == 2) {
digitalWrite(soleniod2Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod2Pin, LOW);
}
if (buttonPushCounter == 3) {
digitalWrite(soleniod3Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod3Pin, LOW);
}
if (buttonPushCounter2 == 1) {
digitalWrite(soleniod4Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod4Pin, LOW);
}
if (buttonPushCounter2 == 2) {
digitalWrite(soleniod5Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod5Pin, LOW);
}
if (buttonPushCounter2 == 3) {
digitalWrite(soleniod6Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound1Pin, HIGH);
// need a delay with abilty to keep doing other stuff
digitalWrite(sound2Pin, HIGH);
} else {
digitalWrite(soleniod6Pin, LOW);
}
if (buttonPushCounter > 2) {
buttonPushCounter = 0;
}
if (buttonPushCounter2 > 2) {
buttonPushCounter2 = 0;
}
}
[/code]