Need help with programming for my project

Hi,
my school has an engineering course. in this course we have to create a project, program it and build it .
The program that i have written so far is to make a servo turn when a pushbutton is pressed. It is in the void loop. When the button is pressed the servo turns 180 degrees. when it is not being pressed it goes back to 0 degrees. what i need help with is the programming this project so that only when 9 buttons are all pushed at the same time the servo will turn and when all of them are not being pushed it turns back to 0 degrees.

here is the program i have written so far:
int pushButton2 = 2;
#include <Servo.h>
Servo myservo;

void setup() {
Serial.begin(9600);
pinMode(pushButton2 ,INPUT);
myservo.attach(9);
}

void loop() {
int buttonState2 = digitalRead (pushButton2);

Serial.println(buttonState2);
if (digitalRead(pushButton2) == true)
{
myservo.write(180);
}
if (digitalRead(pushButton2) == false)
{
myservo.write(0);
}
delay(15);
}

Thanks so much for the help

It is in the void loop.

No, it isn't. It is in the loop [u]function[/u]. void is the return type.

what i need help with is the programming this project so that only when 9 buttons are all pushed at the same time the servo will turn and when all of them are not being pushed it turns back to 0 degrees.

So, you need 9 more switches. Then, you need to read the 9 more switch states, and use an if statement with a bunch of &&s in it.

  if (digitalRead(pushButton2) == true)

The digitalRead() function does NOT return true. Do not pretend it does.

If you only want the motor to run when all 9 buttons are pressed (who is going to press them?) it would be easiest to add all the results from all the digitalRead()s. If the total is not 9 then move the servo to 0 degrees.

...R

Wire the 9 switches in series and you only need 1 digital pin and the same code you have written.

Riva: Wire the 9 switches in series and you only need 1 digital pin and the same code you have written.

+1

...R