urgent help needed with code for Uni project

//This code is when a character is inputted from the keyboard it does the
//sequence.
//When the push button is pressed it switches everything off, debounce code is applied aswell.

can anyone help as i can't seem to get the push button to switch off the lights and vibration motor, when i use the keyboard to input the character 'a' it switches it on i am really puzzled.

const int LED1 = 2;
const int resetButton = 12;
const int redLED = A0;
const int blueLED = A1;
const int greenLED = A2;
const int vibrationMOTOR = A3;

void setup()
{
Serial.begin(9600);
pinMode(resetButton,INPUT);
pinMode(LED1, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode (vibrationMOTOR, OUTPUT);
}

void loop()
{
if (Serial.available() > 0)
{
//Reading the serial port
int inByte = Serial.read();
if (inByte == 'a')
{
digitalWrite(LED1, HIGH);
digitalWrite(vibrationMOTOR, HIGH);
digitalWrite(blueLED, HIGH);
delay(500);
digitalWrite(blueLED, LOW);
digitalWrite(greenLED, HIGH);
delay(500);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
Button();
}
}
}

void Button()
{
if(button_pressed(resetButton))
{
Serial.println("Cleared");
digitalWrite(LED1, LOW);
digitalWrite(vibrationMOTOR, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, LOW);
digitalWrite(blueLED, LOW);
}
}

bool button_pressed(int resetButton)
{
// the following variables are type:long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
static long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 70; // the debounce time; increase if necessary
static int previous = HIGH;
int reading; // store the latest button input (HIGH or LO)
int buttonpress = false; // set true once on new button push (HIGH to LO transition)
static boolean button_previously_LO = false; // remember if button is currently pressed

buttonpress = false;
reading = digitalRead(resetButton);
// check to see if the button has just been pressed
// (i.e. the input went from HIGH to LO), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if ( (reading != previous)) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// check if button LO (pressed)
if ((reading == LOW)) {
if ( ! button_previously_LO ) { // if button already pressed, ignore
buttonpress = true;
button_previously_LO = true;
}
}
else // reading is HIGH so button has been released
button_previously_LO = false;
}
previous = reading; // remember last reading
return buttonpress;
}

How many chances do you have to detect a button press?

(please read the sticky threads at the top of this forum section)

Should have said using Arduino MIni pro 5v 16mhz

Picture of project:

whenever the button is pushed i want it to switch everything off thats all i want it to do and it doesn't seem to work :~

16mhz

Uni project? :astonished:

its Integrated design project other people are doing other bits and then we all integrate it together i'm having problems, its probably something simple but i was first using case statement and i couldn't get the push button working with that, so now am trying if statement and its still not working someone please help.

How many chances do you have to detect a button press?

a don't know what you mean :~

Look at the flow of your sketch.
How many times do the function "Button" get called?
More importantly, how many times does the function "button_pressed" get called?
More importantly still, what is the minimum number of times it needs to get called?

its only being called once a think, am trying to get it working for one sequence before i implement the rest and so far am hitting a brick wall.

its only being called once

Correct.
And the minimum number of times it needs to be called?

I have got it thanks